Re: [fpc-devel] Type+multi helpers overload bug

2022-05-08 Thread Michael Van Canneyt via fpc-devel



On Sun, 8 May 2022, Hairy Pixels via fpc-devel wrote:


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.___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Type+multi helpers overload bug

2022-05-07 Thread Hairy Pixels via fpc-devel
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

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel