Scope of import
DLearner
bmqazwsx123 at gmail.com
Sat May 15 06:55:47 UTC 2021
```
// main
void main() {
import A;
// import B;
import std.stdio;
writeln("Entered main");
fnA1();
writeln("Leaving main");
}
```
```
module A;
void fnA1() {
import B;
import std.stdio;
writeln("Entered fnA1");
fnB1();
writeln("Leaving fnA1");
}
```
```
module B;
void fnB1() {
import std.stdio;
writeln("Entered fnB1");
writeln("Leaving fnB1");
}
```
1. Code above compiles but fails on linker step with 'Error 42
Symbol Undefined'.
To me, unexpected behaviour as imports arranged to pick up
symbols (with minimum scope).
2. Uncommenting the 'import B' in main everything works correctly.
To me, particularly unexpected behaviour as no symbol from B
directly used in main (also undesirable to set scope
unnecessarily wide).
Best regards
More information about the Digitalmars-d-learn
mailing list