Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2021-11

Is this a bug? with A,B do overloaded_in_A_and_B

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

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.

Reply by email