Wrong type helper picked when using type aliases that define new types

Summary

When declaring type helpers for types defined using type aliases that define new types, the wrong helper may be used when resolving function calls on the new type.

Steps to reproduce

{$MODE OBJFPC}
{$MODESWITCH ADVANCEDRECORDS+}

type
   TFoo = record end;
   TBar = type TFoo;
   TBaz = type TFoo;

   TBarHelper = record helper for TBar
      procedure Test();
   end;

   TBazHelper = record helper for TBaz
      procedure Test();
   end;

procedure TBarHelper.Test();
begin
   Writeln('PASS');
end;

procedure TBazHelper.Test();
begin
   Writeln('FAIL');
end;

var
   X: TBar;
begin
   X.Test();
end.

This prints FAIL, but I would expect it to print PASS, because TBar and TBaz are distinct types.

This also fails for class procedure ... static functions:

{$MODE OBJFPC}
{$MODESWITCH ADVANCEDRECORDS+}

type
   TFoo = record end;
   TBar = type TFoo;
   TBaz = type TFoo;

   TBarHelper = record helper for TBar
      class procedure Test(); static;
   end;

   TBazHelper = record helper for TBaz
      class procedure Test(); static;
   end;

class procedure TBarHelper.Test();
begin
   Writeln('PASS');
end;

class procedure TBazHelper.Test();
begin
   Writeln('FAIL');
end;

begin
   TBar.Test();
end.

System Information

  • Operating system: Linux
  • Processor architecture: x86-64
  • Compiler version: trunk compiled on 2025/07/03
  • Device: Computer