Symbol lookup rules and imports
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Mon Dec 8 00:34:07 PST 2014
On 12/2/2014 2:00 PM, H. S. Teoh via Digitalmars-d wrote:
> However, there are major issues with scoped imports currently,
> that make this otherwise ideal solution less-than-ideal, which stem from
> the way 'import' is implemented in D. When the compiler encounters an
> 'import' statement, what it essentially does is to parse the symbols in
> the target module, and add them to the symbol table for the current
> scope.
No, it does not. Each scope has a symbol table of symbols declared in the
current scope,
https://github.com/D-Programming-Language/dmd/blob/master/src/dsymbol.h#L298
and it has an array of imported symbol tables:
https://github.com/D-Programming-Language/dmd/blob/master/src/dsymbol.h#L301
Only if the symbol is not found in the current scope,
https://github.com/D-Programming-Language/dmd/blob/master/src/dsymbol.c#L902
it then looks in the imported symbol tables:
https://github.com/D-Programming-Language/dmd/blob/master/src/dsymbol.c#L910
More information about the Digitalmars-d
mailing list