Bug 4894 – Cannot use the same name for nested functions even though they're in different scopes
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-09-19T01:11:25Z
Last change time
2019-08-18T12:49:31Z
Keywords
bootcamp
Assigned to
No Owner
Creator
Jonathan M Davis
Comments
Comment #0 by issues.dlang — 2010-09-19T01:11:25Z
This fails to compile
void main()
{
{
int nestedFunc(int val)
{
return val;
}
}
{
float nestedFunc(float val)
{
return val;
}
}
}
with the error
d.d(10): Error: declaration nestedFunc is already defined in another scope in main
The functions are in separate scopes. No name shadowing is occurring. I don't see why they can't both exist. If they were variables, there would be no problem. Obviously, this is intentional given the specificity of the error message, but it seems overly restrictive to me. So, I'm submitting it as a feature request that nested functions be allowed to have the same name if they're in separate scopes and no name shadowing/hiding can occur.
Comment #1 by dmitry.olsh — 2018-05-18T08:57:11Z
Seems like a minor limitation, and getting different mangling
Comment #2 by dmitry.olsh — 2018-05-18T08:57:44Z
(In reply to Dmitry Olshansky from comment #1)
> Seems like a minor limitation, and getting different mangling
for each of identical signature functions:
void main()
{
{
int nestedFunc(int val)
{
return val+1;
}
}
{
int nestedFunc(int val)
{
return val+2;
}
}
}
Comment #3 by simen.kjaras — 2019-08-18T12:49:31Z
*** This issue has been marked as a duplicate of issue 4699 ***