Comment #0 by shigekikarita — 2018-10-13T04:48:24Z
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");
}
}
}
Comment #1 by razvan.nitu1305 — 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.
Comment #2 by uplink.coder — 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.
Comment #3 by shigekikarita — 2018-11-27T15:13:03Z
Yes, the current spec defines both with statement and innermost scope are "first". It should be ambiguous.
Comment #4 by shigekikarita — 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");
}
}
}
Comment #5 by robert.schadek — 2024-12-13T19:00:55Z