Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In symbol lookup, with statement becomes stronger than an inner scope import statement #17882

Open
dlangBugzillaToGithub opened this issue Oct 13, 2018 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

karita (@ShigekiKarita) reported this on 2018-10-13T04:48:24Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19305

CC List

  • RazvanN
  • Stefan Koch

Description

I found a breaking change of symbol  from DMD2.073.0. I think this change comes from a conflict between statement spec 4.3.2 and module spec 11.19.1.

see 4.3.2 in https://docarchives.dlang.io/v2.081.0/spec/module.html
see 11.19.1 in https://docarchives.dlang.io/v2.081.0/spec/statement.html#with-statement


running example 
https://wandbox.org/permlink/5bDsMZeqKYh4runs
-------

module a;

enum f = "a";


module b;

enum f = "b";


module main;

import std.stdio;
import a;
import b;


void main() {
    with (a) {
        // 11.19.1 Within the with body the referenced object is searched first for identifier symbols
        assert(f == "a");
        // 4.3.2 When a symbol name is used unqualified, a two-phase lookup will happen. 
        // First, the module scope will be searched, starting from the innermost scope. ...
        // Symbol lookup stops as soon as a symbol is found. 
        // If two symbols with the same name are found at the same lookup phase,
        //  this ambiguity will result in a compilation error.
        import b;
        static if (__VERSION__ >= 2073) {
            assert(f == "a");
        } else {
            assert(f == "b");                    
        }
    }
}
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2018-11-27T12:50:07Z

I don't see what the problem is. master git HEAD compiles this successfully as it should. The with scope takes precedence over imports. The rules are clear. Maybe older versions had a bug in it which was solved.

Closing as invalid. Please reopen if I am missing something.

@dlangBugzillaToGithub
Copy link
Author

uplink.coder commented on 2018-11-27T14:57:39Z

I think this example should cause an ambiguity error.

Or the spec should be amended to explicitly break this tie.

@dlangBugzillaToGithub
Copy link
Author

shigekikarita commented on 2018-11-27T15:13:03Z

Yes, the current spec defines both with statement and innermost scope are "first". It should be ambiguous.

@dlangBugzillaToGithub
Copy link
Author

shigekikarita commented on 2018-11-27T15:22:02Z

For more clear example, 2.083 runs this without any errors.

void main() {
    with (a) {
        {
            import b;
            assert(f == "a");
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant