View Issue Details

IDProjectCategoryView StatusLast Update
0038578FPCCompilerpublic2021-03-10 03:21
ReporterExSystem Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status feedbackResolutionopen 
Platformx86_64-darwinOSMacOS 
Product Version3.3.1 
Summary0038578: [Identifier idents no member.] occurs when calling a method with method generics parameters
Descriptionjust as the title mentioned.
Steps To Reproduce1.compile the project inside the zip file attached.
2.a successful compilation expected, but error produced:
Identifier idents no member "bar".
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

ExSystem

2021-03-04 02:51

reporter  

aaa.zip (2,655 bytes)

ExSystem

2021-03-04 02:53

reporter   ~0129369

Last edited: 2021-03-04 02:53

View 2 revisions

the simple project source listed as below for convenience:

program project1;

{$MODE DELPHI}{$H+}

type
  IFoo = interface(IInterface)
    function getBar(): LongWord;
    property bar: LongWord read getBar;
  end;

  { TBar }

  TBar = class(TInterfacedObject, IFoo)
    function getBar(): LongWord;
  end;

  { TTest }

  TTest = class(TObject)
    procedure test<T: TInterfacedObject, IFoo>(param: LongWord);
  end;

var
  aa: TTest;
  intf: TBar;

{ TTest }

procedure TTest.test<T>(param: LongWord);
begin
  WriteLn('bbb');
end;

{ TBar }

function TBar.getBar(): LongWord;
begin
  WriteLn('aaa');
  Result:=1;
end;

begin
  aa:=TTest.Create();
  intf:=TBar.Create();
  aa.test<TBar>(intf.bar); //Error: Identifier idents no member "bar"
  aa.Free();
  intf.Free();
end.

Sven Barth

2021-03-04 09:21

manager   ~0129373

This has nothing to do with generics, but with how interfaces work. If a class declares that it implements an interface X then this means that it can be cast to interface X, it does not mean that e.g. properties of the interface are available on the class instance. This becomes most apparent if you use interface delegation to implement the interface (without a redirection clause) cause then none of the interface's methods are present in the class instance itself.

ExSystem

2021-03-10 03:21

reporter   ~0129537

my fault:) I gave a wrong test case extracted from my big big project. Please see this test case below, a successful compilation is expected:
====SEE THIS PROJECT CODE====
program project1;

{$MODE DELPHI}{$H+}

type
  IFoo = interface(IInterface)
    function getBar(): LongWord;
    property bar: LongWord read getBar;
  end;

  { TBar }

  TBar = class(TInterfacedObject, IFoo)
    function getBar(): LongWord;
  end;

  { TTest }

  TTest = class(TObject)
    procedure test<T: TInterfacedObject, IFoo>(param: T);
  end;

var
  aa: TTest;
  intf: IFoo;

{ TTest }

procedure TTest.test<T>(param: T);
begin
  WriteLn(param.bar.ToString()); //Error: Identifier idents no member "bar"
  WriteLn('bbb');
end;

{ TBar }

function TBar.getBar(): LongWord;
begin
  WriteLn('aaa');
  Result := 1;
end;

begin
  // a successful compliation expected.
end.

Issue History

Date Modified Username Field Change
2021-03-04 02:51 ExSystem New Issue
2021-03-04 02:51 ExSystem File Added: aaa.zip
2021-03-04 02:53 ExSystem Note Added: 0129369
2021-03-04 02:53 ExSystem Note Edited: 0129369 View Revisions
2021-03-04 09:21 Sven Barth Assigned To => Sven Barth
2021-03-04 09:21 Sven Barth Status new => resolved
2021-03-04 09:21 Sven Barth Resolution open => no change required
2021-03-04 09:21 Sven Barth FPCTarget => -
2021-03-04 09:21 Sven Barth Note Added: 0129373
2021-03-10 03:21 ExSystem Status resolved => feedback
2021-03-10 03:21 ExSystem Resolution no change required => open
2021-03-10 03:21 ExSystem Note Added: 0129537