D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4699 - Functions in peer scopes cannot have the same name
Summary: Functions in peer scopes cannot have the same name
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
: 4894 5882 12881 (view as issue list)
Depends on:
Blocks:
 
Reported: 2010-08-21 00:19 UTC by Eduardo Cavazos
Modified: 2022-08-15 13:56 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Eduardo Cavazos 2010-08-21 00:19:59 UTC
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 Infiltrator 2014-03-18 23:29:45 UTC
Why is this a bug?
Comment 2 Infiltrator 2014-03-19 17:45:25 UTC
*** Issue 5882 has been marked as a duplicate of this issue. ***
Comment 3 Stewart Gordon 2014-03-29 12:21:31 UTC
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 bearophile_hugs 2014-03-29 12:25:35 UTC
(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 yebblies 2014-06-09 13:20:09 UTC
*** Issue 12881 has been marked as a duplicate of this issue. ***
Comment 6 yebblies 2014-06-09 13:21:57 UTC
(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 Simen Kjaeraas 2019-08-18 12:49:31 UTC
*** Issue 4894 has been marked as a duplicate of this issue. ***
Comment 8 RazvanN 2022-08-15 13:56:46 UTC
This has been fixed. The code compiles with the latest master.