Identifier resolution, the great implementation defined mess.

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 21 23:07:26 PDT 2014


On 9/21/2014 4:37 PM, deadalnix wrote:
> On Sunday, 21 September 2014 at 20:05:57 UTC, Walter Bright wrote:
>> On 9/20/2014 10:29 PM, deadalnix wrote:
>>> DMD does very bizarre things. I think I should write a DIP, but time is always
>>> running low...
>>>
>>> Free goodie: when you import, all symbol are resolved via the expected import
>>> resolution mechanism. All ? No, the root package is imported in the local scope.
>>>
>>> foo(int a) {
>>>   import a.b.c;
>>>   // a is now a package and not the parameter a anymore.
>>> }
>>
>> What's bizarre about it? You declared a package symbol 'a' in the local scope
>> with the import declaration.
>>
>
> Because this is not consistent with module level import

Yes, it is.

> and that is not consistent with how local shadowing works.

You can argue that 'a' should be an error to shadow the parameter 'a'. But 
extending this to the contents of the import is not consistent.


> IMO you should fallback to import if local lookup failed.

That's exactly how it does work. It's the SAME code that implements it.

Your misunderstanding appears to be that:

    foo(int a) { int b; }

'a' and 'b' are in the same scope. They are NOT in the same scope.


More information about the Digitalmars-d mailing list