D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4894 - Cannot use the same name for nested functions even though they're in different scopes
Summary: Cannot use the same name for nested functions even though they're in differen...
Status: RESOLVED DUPLICATE of issue 4699
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: bootcamp
Depends on:
Blocks:
 
Reported: 2010-09-19 01:11 UTC by Jonathan M Davis
Modified: 2019-08-18 12:49 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2010-09-19 01:11:25 UTC
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 Dmitry Olshansky 2018-05-18 08:57:11 UTC
Seems like a minor limitation, and getting different mangling
Comment 2 Dmitry Olshansky 2018-05-18 08:57:44 UTC
(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 Simen Kjaeraas 2019-08-18 12:49:31 UTC

*** This issue has been marked as a duplicate of issue 4699 ***