Function passed as a parameter is not found by compiler if "masked" by overloaded function of different time.
Original Reporter info from Mantis: glorfin
-
Reporter name: Viatcheslav
Original Reporter info from Mantis: glorfin
- Reporter name: Viatcheslav
Description:
A unit contains two overloaded functions:
function MyFunc(X,Y:integer):boolean; overload;
function MyFunc(X:integer):boolean; overload;
Another unit has declarations:
type
TTestFunc = function(X:integer):boolean;
procedure GetFuncParam(AMyFunc : TTestFunc);
Compiler generates Error: Incompatible type for arg no. 1: Got "&LtPos;address of function(LongInt;LongInt):Boolean;Register>", expected "&LtPos;procedure variable type of function(LongInt):Boolean;Register>"
If functions MyFunc are declared in different order:
function MyFunc(X:integer):boolean; overload;
function MyFunc(X,Y:integer):boolean; overload;
everything works fine.
Expected behaviour: compiler continues search after wrong overloaded function is encountered and finds the right one regardless of order of definitions.
Steps to reproduce:
- Compile supplied unit overfuncs.pas.
- Try to compile the project overfuncparam.lpr.
- See the error message.
- Go to overfuncs.pas and swap places of different "MyFunc" declarations.
- Compile the unit and project again, and find that it works.
Mantis conversion info:
- Mantis ID: 38705
- Version: 3.2.0