View Issue Details

IDProjectCategoryView StatusLast Update
0024434FPCCompilerpublic2021-02-06 13:53
ReporterMario Ray Mahardhika Assigned ToFlorian  
Status resolvedResolutionfixed 
Product Version2.7.1 
Fixed in Version3.3.1 
Summary0024434: function overloading can be done by differentiating return type only
DescriptionA function can be overloaded only by differentiating the return type. Futhermore, when the function is called, the compiler behaves as if only one of the function is defined.
Steps To ReproduceThe following code demonstrates the behavior (see comments in main block for info):

function f(s: string): string;
  f := '''' + s + '''';

function f(s: string): integer;

  i: Integer;
  i := f('123'); // Error: Incompatible types: got "ShortString" expected "SmallInt"
  WriteLn(f('123')); // Calls function f(s: string): string;
Additional InformationThis behavior is found by my friend, he said in Delphi the code compiles and works. However, he didn't give enough details (what Delphi version, how's the behavior when the function is called, etc.). I will add more after he answers.

FPC 2.6.2 is known to have this behavior, too.
TagsNo tags attached.
Fixed in Revision
Attached Files


has duplicate 0024606 closedJonas Maebe Compiler doesn't complain about overloaded functions with same arguments if their result types differ 
has duplicate 0024805 resolvedJonas Maebe Compiler allows overloaded functions with same parameters but different result types, gets confused 


Max Nazhalov

2013-05-16 13:48

reporter   ~0067715

Last edited: 2013-05-16 16:26

View 2 revisions

It does not compile at least under Delphi5 and DelphiXE. ("Error: E2004 Identifier redeclared: 'f'" on the line with the second function declaration)

Both D5 and DXE allow overloading of return value type, but require distinctive parameter lists in this case (it compiles, as in FPC).

See also:
(seems no difference in text)

Bart Broersma

2021-02-05 16:50

reporter   ~0128785

Fpc now says:
Compiling test.pas
test.pas(6,10) Error: Overloaded functions have the same parameter list
test.pas(1,10) Error: Found declaration: f(ShortString):ShortString[255];
test.pas(14,8) Error: Incompatible types: got "ShortString" expected "SmallInt"
test.pas(17) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\pp\bin\i386-win32\ppc386.exe returned an error exitcode

So, this overloading isn't allowed anymore, which is correct.

IMO this should be resolved as "fixed".


2021-02-06 13:53

administrator   ~0128796

@Bart: Thanks for checking. I added a test so it will not creep in again for sure.

Issue History

Date Modified Username Field Change
2013-05-15 17:42 Mario Ray Mahardhika New Issue
2013-05-16 13:48 Max Nazhalov Note Added: 0067715
2013-05-16 16:26 Max Nazhalov Note Edited: 0067715 View Revisions
2013-06-17 11:13 Jonas Maebe Relationship added has duplicate 0024606
2013-08-02 09:40 Jonas Maebe Relationship added has duplicate 0024805
2021-02-05 16:50 Bart Broersma Note Added: 0128785
2021-02-06 13:53 Florian Assigned To => Florian
2021-02-06 13:53 Florian Status new => resolved
2021-02-06 13:53 Florian Resolution open => fixed
2021-02-06 13:53 Florian Fixed in Version => 3.3.1
2021-02-06 13:53 Florian FPCTarget => -
2021-02-06 13:53 Florian Note Added: 0128796