Compiler behavior when functions/procedures have the same name and parameters lazarus / 62-General ---------------------------------------------------------------------- simone · 2022-04-16 09:18 Just out of curiosity, I would like to know if and how the compiler behavior is defined in the following cases: 1) There are a procedure and a function with the same name and the same list of formal parameters: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; procedure Calc(Value : integer);begin  writeln('Procedure:',Value);end; function Calc(Value :integer):integer;begin  writeln('Function:',Value);  Result:=-1;end; begin  Calc(1);  //X:=Calc(2);  //compiler error  readln;end. It seems to me that in this case the function is always ignored. The compiler gives an error if you try to call it, but it does not report the homonymy between procedure and function. 2) There are two functions with the same name and the same list of formal parameters, but with a different type of result: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; function Calc(Value :integer):integer;begin  writeln('Integer Function:',Value);  Result:=-1;end; function Calc(Value :integer):real;begin  writeln('Float Function:',Value);  Result:=-1;end; begin  Calc(1); //the first function is always called  readln;end. In this case it seems to me that the second function is always ignored. The compiler does not report the homonymy between the two functions. These situations are technically not related to overloading because the list of formal parameters is identical. But are these behaviors defined? Wouldn't it be appropriate at least to have a compiler warning? Thanks in advance. ---------------------------------------------------------------------- 440bx · 2022-04-16 09:35 You found a bug. Neither program should compile.  In both cases Calc is a duplicate identifier. Delphi refuses both of them.  HTH. ETA: in the second program, it should complain that the signatures are the same (instead of declaring a "duplicate identifier" which is what it should do for the first program.) ---------------------------------------------------------------------- Josh · 2022-04-16 09:49 hi when run in lazarus, neither will compile as expected. ---------------------------------------------------------------------- 440bx · 2022-04-16 09:59 Just FYI, FPC v3.0.4 compiled both examples from Lazarus. I didn't try compiling with a newer version of FPC. ---------------------------------------------------------------------- simone · 2022-04-16 09:59 With the current version of Fpc (3.2.2), I have errors only in delphi mode. ---------------------------------------------------------------------- Bart · 2022-04-16 16:23 Current fpc trunk  ('main') will reject both examples: The first: Code: [Select]test.pas(103,14) Error: Overloaded functions have the same parameter list test.pas(98,15) Error: Found declaration: Calc(LongInt); test.pas(114) Fatal: There were 2 errors compiling module, stopping The second: Code: [Select]test.pas(105,14) Error: Overloaded functions have the same parameter list test.pas(99,14) Error: Found declaration: Calc(LongInt):LongInt; test.pas(115) Fatal: There were 2 errors compiling module, stopping (Never mind the line numbers) Bart