Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2022-05

Type+multi helpers overload bug

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hairy Pixels

Basically it looks like multi helpers don’t actually work with overloaded methods and simply choses the last helper declared. Should I fix this? Seems unlikely we would not notice this before but maybe we did.

{$modeswitch typehelpers}
{$modeswitch multihelpers}
type
  TMyHelper1 = type helper for integer
    procedure DoThis(f: integer);
  end;
  TMyHelper2 = type helper for integer
    procedure DoThis(f: string);
  end;
procedure TMyHelper1.DoThis(f: integer);
begin
  writeln(self, ' => ', f);
end;
procedure TMyHelper2.DoThis(f: string);
begin
  writeln(self, ' => ', f);
end;
var
  i: integer = 0;
begin
  i.DoThis(0);  // Got "ShortInt", expected “ShortString"

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Hairy Pixels
Hairy Pixels wrote 27 lines
Basically it looks like multi helpers don’t actually work with overloaded methods and simply choses the last helper declared. Should I fix this? Seems unlikely we would not notice this before but maybe we did. {$modeswitch typehelpers} {$modeswitch multihelpers} type TMyHelper1 = type helper for integer procedure DoThis(f: integer); end; TMyHelper2 = type helper for integer procedure DoThis(f: string); end; procedure TMyHelper1.DoThis(f: integer); begin writeln(self, ' => ', f); end; procedure TMyHelper2.DoThis(f: string); begin writeln(self, ' => ', f); end; var i: integer = 0; begin i.DoThis(0); // Got "ShortInt", expected “ShortString"

If you fix this, then I think you should make sure it is only done when the overload; keyword is present. For regular classes, searching for an overload match stops also at the current class (? unit) if the overload keyword is not present.

Michael.

Reply by email