Bug 2789 – Functions overloads are not checked for conflicts

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-04-03T08:35:45Z
Last change time
2023-10-26T18:06:40Z
Keywords
accepts-invalid, pull
Assigned to
yebblies
Creator
Witold Baryluk
Blocks
2703, 14147
See also
https://issues.dlang.org/show_bug.cgi?id=12694

Comments

Comment #0 by witold.baryluk+d — 2009-04-03T08:35:45Z
cclass A { int m() { return 1; } float m() { return 2.0; } } class B { int m() { return 1; } int m() { return 2; } } void main() { auto a = new A(); assert(a.m() == 1); auto b = new B(); assert(b.m() == 1); } /+ dmd -c bugcopy.d bugcopy.d(23): function bugcopy.A.m called with argument types: () matches both: bugcopy.A.m() and: bugcopy.A.m() bugcopy.d(25): function bugcopy.B.m called with argument types: () matches both: bugcopy.B.m() and: bugcopy.B.m() Exit 1 +/ Without main this program compiles without any warning or error. This connected with for example overloding over aliases/or const can lead to problems. class B { int m(S[] c) { return 1; } int m(invariant(S)[] c) { return 2; } } If S is already invariant, then this code is erratic, but compiler will not report it to user.
Comment #1 by smjg — 2009-04-15T11:08:07Z
This was a bug in the D1 line ages ago - it seems for some reason the fix wasn't applied to the D2 line. BTW no classes are needed to show the bug - it happens with global functions just as well.
Comment #2 by witold.baryluk+d — 2010-01-31T09:04:23Z
(In reply to comment #1) > This was a bug in the D1 line ages ago - it seems for some reason the fix > wasn't applied to the D2 line. BTW no classes are needed to show the bug - it > happens with global functions just as well. Hmm. You are right, global functions also have this problem. The problem is that if you don't use this functions, and they have different return types, even linker will not give you any error.
Comment #3 by yebblies — 2012-01-29T07:25:12Z
The check for D2 was disabled because it didn't play nice with const, according to comments in FuncDeclaration::overloadInsert.
Comment #4 by yebblies — 2012-01-29T07:32:55Z
Comment #5 by yebblies — 2012-01-29T07:34:28Z
*** Issue 1003 has been marked as a duplicate of this issue. ***
Comment #6 by yebblies — 2012-02-14T19:37:33Z
*** Issue 895 has been marked as a duplicate of this issue. ***
Comment #7 by yebblies — 2013-08-20T07:53:15Z
*** Issue 10590 has been marked as a duplicate of this issue. ***
Comment #8 by yebblies — 2013-11-14T04:25:09Z
*** Issue 11295 has been marked as a duplicate of this issue. ***
Comment #9 by yebblies — 2013-11-24T05:19:09Z
*** Issue 8731 has been marked as a duplicate of this issue. ***
Comment #10 by yebblies — 2015-01-26T11:24:03Z
*** Issue 13896 has been marked as a duplicate of this issue. ***
Comment #11 by k.hara.pg — 2015-02-08T14:45:22Z
Comment #12 by github-bugzilla — 2015-02-16T20:29:41Z
Comment #13 by github-bugzilla — 2015-02-18T03:42:06Z
Comment #14 by github-bugzilla — 2015-02-21T09:17:50Z
Comment #15 by alanb — 2015-06-14T08:02:17Z
This bug report may be related or a duplicate https://issues.dlang.org/show_bug.cgi?id=13283 The problem persists in dmd v2.067.1 It is particularly nasty since even the linker won't catch it in some cases. For example: main_lib.d --------------------------- module main_lib; import std.stdio; alias t_TaskFunction = void function(); // duplicate overloads that should not compile void Task(){ writeln("A"); } void Task(){ writeln("B"); } main.d --------------------------- import main_lib; int main() { t_TaskFunction TaskFunction = &Task; // ??? TaskFunction(); return 0; } $dmd main_lib.d -lib -O -oflibmain_lib.a $dmd main2.d -O -L-L./ -L-lmain_lib -ofmain $./main Output is "A" on my system.
Comment #16 by greensunny12 — 2018-02-08T00:03:53Z
Comment #17 by greensunny12 — 2018-03-01T05:08:55Z
Temporarily reopened due to regressions reported. See also https://github.com/dlang/dmd/pull/7969, https://github.com/dlang/dmd/pull/7577
Comment #18 by witold.baryluk+d — 2020-05-15T16:26:07Z
Interesting, gdc 9.2 does report duplicate: <source>:16:6: error: example.B.m at <source>:16:6 conflicts with example.B.m at <source>:12:6 16 | int m() { The issue is still present in dmd nightly, dmd 2.089, ldc 1.20, ldc trunk. Link with an example: https://godbolt.org/z/xE6fK7
Comment #19 by ibuclaw — 2020-08-03T10:24:11Z
(In reply to Witold Baryluk from comment #18) > Interesting, gdc 9.2 does report duplicate: > > <source>:16:6: error: example.B.m at <source>:16:6 conflicts with > example.B.m at <source>:12:6 > > 16 | int m() { > > > > The issue is still present in dmd nightly, dmd 2.089, ldc 1.20, ldc trunk. > > Link with an example: https://godbolt.org/z/xE6fK7 This is checked in the codegen pass. Would be better if the front-end did it for us.
Comment #20 by witold.baryluk+d — 2023-10-26T00:06:03Z
This appears to have been fixed at some point, as I cannot reproduce it anymore: $ dmd t.d t.d(6): Error: function `t.A.m()` conflicts with previous declaration at t.d(2) t.d(16): Error: function `t.B.m()` conflicts with previous declaration at t.d(12) $ ldc t.d ldc2 ldc-build-runtime ldc-profdata ldc-prune-cache $ ldc2 t.d t.d(6): Error: function `t.A.m()` conflicts with previous declaration at t.d(2) t.d(16): Error: function `t.B.m()` conflicts with previous declaration at t.d(12) $ gdc t.d t.d:6:11: error: function ‘t.A.m()’ conflicts with previous declaration at t.d:2:9 6 | float m() { | ^ t.d:16:9: error: function ‘t.B.m()’ conflicts with previous declaration at t.d:12:9 16 | int m() { | ^ Same with global functions. DMD64 D Compiler v2.105.2 LDC - the LLVM D compiler (1.30.0): based on DMD v2.100.1 and LLVM 14.0.6 gdc (Debian 13.2.0-5) 13.2.0
Comment #21 by witold.baryluk+d — 2023-10-26T00:15:58Z
dmd 2.094.2 - incorrectly compiles successfully dmd 2.095.0 - correctly shows error and aborts
Comment #22 by witold.baryluk+d — 2023-10-26T00:19:43Z
Ah yes of course: https://dlang.org/changelog/2.095.0.html#duplicate-implementations-deprecation Unfortunately this changelog does not link bugzilla or pull requests with fixes.
Comment #23 by b2.temp — 2023-10-26T18:06:40Z