View Issue Details

IDProjectCategoryView StatusLast Update
0033604FPCCompilerpublic2020-09-07 11:26
ReporterZoran Vučenović Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.1.1 
Fixed in Version3.3.1 
Summary0033604: Overloaded routines with same arguments pass compilation.
DescriptionFunction with same name and same parameters, declared in same scope, but only with different result type pass compilation.

If the result type is same, then compiler breaks with Error: overloaded functions have the same parameter list
The two routines with same name same parameter list are identical from the "overloading point of view", regardless of the result type. So, this is a bug, right?
Steps To ReproduceThis should not compile, but it does:

program Project1;

{$mode objfpc}{$H+}

procedure TestOverload(N: Integer);
begin
  writeln('Version with no result called');
end;

function TestOverload(N: Integer): Integer;
begin
  writeln('Integer version called');
  Result := 0;
end;

function TestOverload(N: Integer): String;
begin
  writeln('String version called');
  Result := '';
end;

begin
  TestOverload(0);
end.
Additional InformationRunning this program prints "Version with no result called". So it just works with one version.

When I change the order and put the integer version on top, it gets called, so, it seems that the first version declared on top of the others gets executed.
TagsNo tags attached.
Fixed in Revision45973
FPCOldBugId
FPCTarget-
Attached Files

Activities

Thaddy de Koning

2018-04-14 18:51

reporter   ~0107788

The same is true for {$mode delphi} even after introducing overloads:
program Project1;

{$mode delphi}{$H+}

procedure TestOverload(N: Integer);overload;
begin
  writeln('Version with no result called');
end;

function TestOverload(N: Integer): Integer;overload;
begin
  writeln('Integer version called');
  Result := 0;
end;

function TestOverload(N: Integer): String;overload;
begin
  writeln('String version called');
  Result := '';
end;

begin
  TestOverload(0);
end.

This also picks the first only without error or warning.

Thaddy de Koning

2018-04-14 22:14

reporter   ~0107790

Last edited: 2018-04-14 22:20

View 3 revisions

Isn't this a regression? I can't remember I encountered it before. I can remember the compiler gave/gives proper feedback. "Can't determine which overloaded function to call" but maybe I am wrong again and was that message due to param size

Bart Broersma

2018-04-15 10:22

reporter   ~0107792

At least 3.0.0 behaves the same.

delfion

2020-09-05 08:44

reporter   ~0125387

Revision 46661 produces:
>fpc overload.pas
Free Pascal Compiler version 3.3.1 [2020/08/23] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling overload.pas
overload.pas(10,10) Error: Overloaded functions have the same parameter list
overload.pas(5,11) Error: Found declaration: TestOverload(LongInt);
overload.pas(16,10) Error: Overloaded functions have the same parameter list
overload.pas(5,11) Error: Found declaration: TestOverload(LongInt);
overload.pas(10,10) Error: Found declaration: TestOverload(LongInt):LongInt;
overload.pas(25) Fatal: There were 5 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode

Zoran Vučenović

2020-09-05 11:05

reporter   ~0125388

Thanks delfion, I see now that Sven says in forum that he fixed it recently: https://forum.lazarus.freepascal.org/index.php/topic,51331.msg376683.html#msg376683

I am going to ask him there to take this and resolve.

Sven Barth

2020-09-07 10:16

manager   ~0125416

Thank you for bringing this to my attention. :)

Please close.

Zoran Vučenović

2020-09-07 11:26

reporter   ~0125419

Thank you.

Issue History

Date Modified Username Field Change
2018-04-13 15:06 Zoran Vučenović New Issue
2018-04-14 18:51 Thaddy de Koning Note Added: 0107788
2018-04-14 22:14 Thaddy de Koning Note Added: 0107790
2018-04-14 22:15 Thaddy de Koning Note Edited: 0107790 View Revisions
2018-04-14 22:20 Thaddy de Koning Note Edited: 0107790 View Revisions
2018-04-15 10:22 Bart Broersma Note Added: 0107792
2020-09-05 08:44 delfion Note Added: 0125387
2020-09-05 11:05 Zoran Vučenović Note Added: 0125388
2020-09-07 10:16 Sven Barth Assigned To => Sven Barth
2020-09-07 10:16 Sven Barth Status new => resolved
2020-09-07 10:16 Sven Barth Resolution open => fixed
2020-09-07 10:16 Sven Barth Fixed in Version => 3.3.1
2020-09-07 10:16 Sven Barth Fixed in Revision => 45973
2020-09-07 10:16 Sven Barth FPCTarget => -
2020-09-07 10:16 Sven Barth Note Added: 0125416
2020-09-07 11:26 Zoran Vučenović Status resolved => closed
2020-09-07 11:26 Zoran Vučenović Note Added: 0125419