[fpc-devel] Is this a bug? with A,B do overloaded_in_A_and_B

Martin Frb lazarus at mfriebe.de
Thu Nov 25 14:14:28 CET 2021


 From the doc 
https://www.freepascal.org/docs-html/current/ref/refsu62.html#x172-19600013.2.8
> any variable reference, or method reference is checked to see if it is 
> a field or method of the record or object or class

In the below code both objects have a "procedure def;", but they differ 
in their arguments.

So according to the doc, it checks if "foo()" (empty args) is on TX.
It is not, so should it then find "TBar.foo()"?

The issue also happens, if TBar.foo take a boolean arg, and the call is 
"foo(true)". So "empty" is not a special case.


Just to add: I just came across it while testing something else. I don't 
need this.
I actually wonder if it is better as it is, since allowing it introduces 
new risks...
Though then, maybe the docs should state the intention.
No idea WDD.



program Project1;
{$mode objfpc}{$H+}
type

   TBar = class
     procedure def; overload;
   end;

   TX = class
     procedure def(a: integer); overload;
   end;

procedure TX.def(a: integer);overload;
begin
end;

procedure TBar.def;overload;
begin
end;

var
   b: TBar;
   x: TX;

begin
   with b do
     with x do
       def;
end.



More information about the fpc-devel mailing list