[Issue 13808] Scoped std.string:format import in SysTime hijacks UFCS

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Dec 2 07:37:32 PST 2014


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

hsteoh at quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh at quickfur.ath.cx

--- Comment #2 from hsteoh at quickfur.ath.cx ---
Argh... yet another scoped import pathological behaviour. Apparently putting an
import in the body of a struct S pulls symbols into the struct's namespace, so
that S.symbol now refers to the imported symbol.

This is really nasty, and greatly limits the usefulness of scoped imports, for
example:

-----
// mod.d
module mod;
struct S {
    // This is necessary for myFunc, and we can't move it inside myFunc,
    // because we need it in the sig constraint
    import std.range.primitives : isInputRange;

    auto myFunc(R)(R input)
        if (isInputRange!R)
    { ... }
}

// main.d
import mod;
void main() {
    S s;
    static if (s.isInputRange!(int[])) { // this actually works :-(
       ...
    }
    static if (isInputRange!(int[])) { // whereas this doesn't compile
    }
}
-----

Note that making the import in S static doesn't help, because static imports
cannot bind specific symbols, so you have to alias specific import symbols...
but that again leaks them to the outside via UFCS.

This is no longer just about std.datetime, this is a glaring hole in the import
system.

--


More information about the Digitalmars-d-bugs mailing list