View Issue Details

IDProjectCategoryView StatusLast Update
0038851pas2jstranspilerpublic2021-05-04 10:59
ReporterWagner Landgraf Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Summary0038851: Overloaded methods not properly solved when used in property setter
DescriptionWhen 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 ReproduceTry 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 InformationIf you swap the order of Add methods, leaving the one that receives a string parameter as the last one, it compiles fine.
TagsNo tags attached.
Fixed in Revision
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2021-05-04 10:52 Wagner Landgraf New Issue
2021-05-04 10:59 Mattias Gaertner Assigned To => Mattias Gaertner
2021-05-04 10:59 Mattias Gaertner Status new => assigned