Error or a new behaviour with 2.071.0

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 8 06:44:17 PDT 2016


On 4/8/16 9:31 AM, Daniel Kozak wrote:
> On Friday, 8 April 2016 at 13:28:15 UTC, Daniel Kozak wrote:
>> From https://dlang.org/spec/attribute.html#ProtectionAttribute
>>
>> Protection does not participate in name lookup. In particular, if two
>> symbols with the same name are in scope, and that name is used
>> unqualified then the lookup will be ambiguous, even if one of the
>> symbols is inaccessible due to protection. For example:
>>
>> module A;
>> private class Foo {}
>> module B;
>> public class Foo {}
>> import A;
>> import B;
>>
>> Foo f1; // error, could be either A.Foo or B.Foo
>> B.Foo f2; // ok
>>
>>
>> But Foo f1; // works ok now with 2.071.0
>
> Btw:
>
> import a : Foo;
>
> Foo f1; // works OK even if Foo is private

Someone just filed this morning:

https://issues.dlang.org/show_bug.cgi?id=15896

> Or even worse
>
> import a : Foo;
> import b;
>
> Foo f1; // works OK use a.Foo

Note, import rules here say a.Foo is now a LOCAL symbol. It's like you did:

import a;
alias Foo = a.Foo;

This trumps any other imports. This is a long-standing rule that was not 
implemented properly in previous versions. You can get the old behavior 
back I think by doing -transition=import for dmd.

-Steve


More information about the Digitalmars-d mailing list