Bug 4699 – Functions in peer scopes cannot have the same name
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-08-21T00:19:59Z
Last change time
2022-08-15T13:56:46Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Eduardo Cavazos
Comments
Comment #0 by wayo.cavazos — 2010-08-21T00:19:59Z
This program produces an error:
void main ()
{
{ int f0 () { return 10 ; } }
{ int f0 () { return 20 ; } }
}
$ rdmd test_scope_a.d
test_scope_a.d(6): Error: declaration f0 is already defined in another scope in main
Comment #1 by lt.infiltrator — 2014-03-18T23:29:45Z
Why is this a bug?
Comment #2 by lt.infiltrator — 2014-03-19T17:45:25Z
*** Issue 5882 has been marked as a duplicate of this issue. ***
Comment #3 by smjg — 2014-03-29T12:21:31Z
Because the two functions named f0 are in disjoint scopes, the compiler shouldn't care about the fact that they have the same name.
I can see a problem in that at the moment the mangled names of the two functions would clash. So this is presumably a temporary restriction in the compiler pending a name mangling scheme that avoids this.
Comment #4 by bearophile_hugs — 2014-03-29T12:25:35Z
(In reply to comment #3)
> So this is presumably a temporary restriction in the
> compiler pending a name mangling scheme that avoids this.
Walter could answer if this restriction is temporary or not.
Comment #5 by yebblies — 2014-06-09T13:20:09Z
*** Issue 12881 has been marked as a duplicate of this issue. ***
Comment #6 by yebblies — 2014-06-09T13:21:57Z
(In reply to bearophile_hugs from comment #4)
>
> Walter could answer if this restriction is temporary or not.
This is not an intentional limitation, and will be fixed eventually.
Comment #7 by simen.kjaras — 2019-08-18T12:49:31Z
*** Issue 4894 has been marked as a duplicate of this issue. ***
Comment #8 by razvan.nitu1305 — 2022-08-15T13:56:46Z
This has been fixed. The code compiles with the latest master.