Overloaded methods not properly solved when used in property setter
Original Reporter info from Mantis: wlandgraf
-
Reporter name: Wagner Landgraf
Original Reporter info from Mantis: wlandgraf
- Reporter name: Wagner Landgraf
Description:
When the property setter method has several overloaded versions, like the following:
procedure Add(const Name: string; const Value: string); overload;
procedure Add(const Name: string; const Value: Integer); overload;
function Get(const Name: string): string;
property Members[const Name: string]: string read Get write Add; default;
The transpiler can't always find the proper overloaded version.
Steps to reproduce:
Try to compile the following project. You will get the following error:
[Error] Project5.dpr(19): Incompatible type arg no. 2: Got "Integer", expected "String"
program Project5;
{$APPTYPE CONSOLE}
uses
js;
type
TFoo = class
strict private
FObj: TJSObject;
public
constructor Create;
procedure Add(const Name: string; const Value: string); overload;
procedure Add(const Name: string; const Value: Integer); overload;
function Get(const Name: string): string;
property Members[const Name: string]: string read Get write Add; default;
end;
{ TFoo }
procedure TFoo.Add(const Name: string; const Value: Integer);
begin
FObj[Name] := Value;
end;
procedure TFoo.Add(const Name, Value: string);
begin
FObj[Name] := Value;
end;
constructor TFoo.Create;
begin
FObj := TJSObject.new;
end;
function TFoo.Get(const Name: string): string;
begin
Result := string(FObj[Name]);
end;
var
Foo: TFoo;
begin
Foo := TFoo.Create;
Foo['test'] := 'ok';
WriteLn(Foo['test']);
end.
Additional information:
If you swap the order of Add methods, leaving the one that receives a string parameter as the last one, it compiles fine.
Mantis conversion info:
- Mantis ID: 38851