Bug 12735 – imports via mixin template become public imports

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-12T05:24:04Z
Last change time
2022-08-25T10:00:52Z
Keywords
accepts-invalid, pull
Assigned to
No Owner
Creator
det
See also
https://issues.dlang.org/show_bug.cgi?id=15925

Comments

Comment #0 by 2krnk — 2014-05-12T05:24:04Z
if module demo_i has an import declaration via mixin template it automatically becomes a public import (that can be seen/used in all modules importing demo_i). (only tested with DMD 2.064.2) ---- module demo_i; mixin template imp(){ import std.algorithm; } mixin imp!(); ---- ---- module demo; import std.stdio; import demo_i; enum teststr = "This should not work!"; void main(string[] args) { writeln( canFind(teststr,"not") ); // works & prints "true"! } ----
Comment #1 by andrej.mitrovich — 2014-05-12T10:46:10Z
Can confirm, also in git-head.
Comment #2 by nicolas.jinchereau — 2014-11-30T18:47:29Z
bump ////// module one; int someSymbol = 1; ////// module two; import one; ////// module main; import two; void main() { enum hasMember = __traits(hasMember, two, "someSymbol"); writeln(hasMember.stringof); // "true" enum compiles = __traits(compiles, { __traits(getMember, two, "someSymbol"); }); writeln(compiles.stringof); // "false" // Error: undefined identifier 'someSymbol' // writeln(__traits(getMember, two, "someSymbol").stringof); }
Comment #3 by k.hara.pg — 2015-02-23T06:34:03Z
Comment #4 by 2krnk — 2016-07-18T03:41:30Z
surprisingly, this issue is still not fixed in DMD 2.071.1. surprising, because if the template would be mixed in the same module, the import would be invisible.
Comment #5 by razvan.nitu1305 — 2022-08-25T10:00:52Z
This has been fixed in git master. The original bug report fails compilation with: " Error: undefined identifier `canFind`" and the sample code presented in https://issues.dlang.org/show_bug.cgi?id=12735#c2 now prints false twice.