[Issue 17630] DMD treats imports as public imports when selectively imported

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 12 13:45:36 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17630

--- Comment #1 from Seb <greensunny12 at gmail.com> ---


Without the selective import:

test17630a.ScopeDsymbol::search(ident='Erase', flags=x0)
object.ScopeDsymbol::search(ident='Erase', flags=x1)
test17630b.ScopeDsymbol::search(ident='Erase', flags=x1)
    found in locals = 'test17630b.Erase'
test17630a.ScopeDsymbol::search(ident='Erase', flags=x28)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x30)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x28)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x30)
__anonymous.ScopeDsymbol::search(ident='Erase', flags=x8)
    found in locals = '__anonymous.Erase'



With the selective import in foo:

__anonymous.ScopeDsymbol::search(ident='Erase', flags=x8)
__anonymous.ScopeDsymbol::search(ident='Erase', flags=x8)
fail17630.ScopeDsymbol::search(ident='Erase', flags=x28)
__anonymous.ScopeDsymbol::search(ident='Erase', flags=x28)
__anonymous.ScopeDsymbol::search(ident='Erase', flags=x10)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x1)
__anonymous.ScopeDsymbol::search(ident='Erase', flags=x10)
fail17630.ScopeDsymbol::search(ident='Erase', flags=x30)
object.ScopeDsymbol::search(ident='Erase', flags=x1)
...
fail_compilation/fail17630.d(11): Error: undefined identifier Erase


With a selective import of another symbol in bar:


test17630b.ScopeDsymbol::search(ident='NoErase', flags=x0)
    found in locals = 'test17630b.NoErase'
test17630b.ScopeDsymbol::search(ident='NoErase', flags=x28)
    found in locals = 'test17630b.NoErase'
test17630a.ScopeDsymbol::search(ident='Erase', flags=x0)
object.ScopeDsymbol::search(ident='Erase', flags=x1)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x2)
object.ScopeDsymbol::search(ident='Erase', flags=x3)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x2)
object.ScopeDsymbol::search(ident='Erase', flags=x3)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x2)
object.ScopeDsymbol::search(ident='Erase', flags=x3)
test17630a.ScopeDsymbol::search(ident='Erase', flags=x2)
fail_compilation/fail17630.d(9): Error: module imports.test17630a import
'Erase' not found, did you mean alias 'NoErase'?


Full test case for the DMD test suite:

diff --git a/test/fail_compilation/fail17630.d
b/test/fail_compilation/fail17630.d
new file mode 100644
index 000000000..08fe72a36
--- /dev/null
+++ b/test/fail_compilation/fail17630.d
@@ -0,0 +1,12 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail17630.d(12): Deprecation: imports.test17630a.Erase is not
visible from module fail17630
+---
+*/
+void main()
+{
+    import imports.test17630a : Erase;
+    //import imports.test17630a; // A non-selective import correctly errors
+    assert(Erase == 2);
+}
diff --git a/test/fail_compilation/imports/test17630a.d
b/test/fail_compilation/imports/test17630a.d
new file mode 100644
index 000000000..68003b1f9
--- /dev/null
+++ b/test/fail_compilation/imports/test17630a.d
@@ -0,0 +1,4 @@
+module imports.test17630a;
+//import imports.test17630b; // works __falsely__ as public import
+//import imports.test17630b : Erase; // <- works __falsely__ as public import
+import imports.test17630b : NoErase; // <- works correctly as private import
diff --git a/test/fail_compilation/imports/test17630b.d
b/test/fail_compilation/imports/test17630b.d
new file mode 100644
index 000000000..c02f4f88a
--- /dev/null
+++ b/test/fail_compilation/imports/test17630b.d
@@ -0,0 +1,3 @@
+module imports.test17630b;
+int Erase = 2;
+int NoErase = 3;

--


More information about the Digitalmars-d-bugs mailing list