Identifier resolution, the great implementation defined mess.

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 21 14:17:37 PDT 2014


On Sun, 21 Sep 2014 13:04:49 -0700
Walter Bright via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> I don't know what mental model people have for how lookups work, but
> the above algorithm is how it actually works.
i believe that people expect this:

  void foo (int a) {
    import a;
    a.bar(); // here we use 'a' module
    xyzzy(); // it's actually 'a.xyzzy', and 'a as module' is implicit
    writeln(a); // here we use 'int a' argument
  }

i.e. symbol resolver will try argument/local name first, and only if it
failed tries to search in module.

or, more complicated sample:

  struct A { int bar; int baz; }
  void foo (in A a) {
    import a;
    a.bar(); // KABOOM, conflicting names
    xyzzy(); // it's actually 'a.xyzzy', and 'a as module' is implicit
    writeln(a); // KABOOM (both module and arg are complex types
    writeln(a.baz); // it's ok until module 'a' doesn't have 'baz'
  }

i'm not saying that this is how things *must* work, but this is what
one excepts, i think.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140922/f66f1042/attachment.sig>


More information about the Digitalmars-d mailing list