On 9/20/2014 10:29 PM, deadalnix wrote:
DMD does very bizarre things. I think I should write a DIP, but time is always
running low...

Free goodie: when you import, all symbol are resolved via the expected import
resolution mechanism. All ? No, the root package is imported in the local scope.

foo(int a) {
   import a.b.c;
   // a is now a package and not the parameter a anymore.
}

What's bizarre about it? You declared a package symbol 'a' in the local scope with the import declaration.

The way imports (and mixin templates) work for symbol lookup is completely consistent.

You could reasonably argue that since package 'a' shadows parameter 'a' in the same way that this issues an error:

  foo(int a) {
    double a;
  }

but, again, there is nothing bizarre about the import name lookup.


Lookup rules are straightforward:

  scope is current scope
  do {
      look up name in scope
      if name is found, done!
      look up name in imports imported into scope
      if name is found, done!
      set scope to enclosing scope
   } while scope exists

I don't know what mental model people have for how lookups work, but the above algorithm is how it actually works.

Reply via email to