Identifier resolution, the great implementation defined mess.

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 22 01:06:15 PDT 2014


On 9/22/14, 12:09 AM, Walter Bright wrote:
> On 9/21/2014 11:36 PM, Jacob Carlborg wrote:
>> You better write down the scope rules as well. It gets complicated
>> with base
>> classes, template mixins and all features available in D.
>
> Sure, I had thought they were.
>
> BTW, template mixins work exactly like imports. See "Mixin Scope" here:
> https://dlang.org/template-mixin

D lookup rules are logical and relatively simple.

In the case of local imports however, there's definitely an element of 
surprise, and also an issue akin to hijacking. Consider:

void main(string[] args) {
    import some_module;
    ... use args ...
}

Let's assume module "some_module" does not define a name "args". All 
works fine.

Time goes by, some_module gets updated to also define the name "args". 
Now this application is recompiled and may actually compile 
successfully, but the semantics has changed - it doesn't use the "args" 
in the parameter list, but instead the symbol exported by some_module.

That's clearly something difficult to ignore. It's one of those cases in 
which logical and relatively simple doesn't fit the bill the same way 
that a pair of pants built out of simple shapes like cylinders and 
hemispheres won't be a good fit.

We must look into this.


Andrei



More information about the Digitalmars-d mailing list