Name lookups in D
Steven Schveighoffer
schveiguy at gmail.com
Mon Nov 16 13:07:21 UTC 2020
On 11/15/20 5:38 PM, Paul Backus wrote:
> On Sunday, 15 November 2020 at 22:20:12 UTC, Dibyendu Majumdar wrote:
>> This fails:
>>
>> module a.b.m;
>>
>> int hello() {
>> return 42;
>> }
>>
>> extern (C) void main() {
>> assert (a.b.m.hello() == 42);
>> }
>>
>> Is it supposed to?
>
> Yes, the fully-qualified name of a module is not in scope unless you
> `static import` it.
This isn't true. you can import a module and still use the FQN:
import std.stdio;
std.stdio.writeln("bar"); // OK
Note, if the module name is a single identifier, you can use it.
This seems like a weird limitation based on the fact that the package
isn't defined.
It was introduced when the imports were fixed, but I'm not sure this was
intentional.
If I put the above code in, and use the wayback compiler machine at
run.dlang.io:
Up to 2.070.2: Success and no output
2.071.2 to 2.078.1: Success with output: onlineapp.d(7): Deprecation:
package a.b is not accessible here
2.079.1 to 2.083.1: Success with output: onlineapp.d(7): Deprecation:
package `a.b` is not accessible here
2.084.1 to 2.086.1: Failure with output: onlineapp.d(7): Error: package
`a.b` is not accessible here
Since 2.087.1: Failure with output: onlineapp.d(7): Error:
undefined identifier `b` in package `a`, perhaps add `static import a.b;`
IMO, you should be able to access the package you are defined in.
-Steve
More information about the Digitalmars-d
mailing list