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

RazvanN <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #2 from RazvanN <[email protected]> ---
Yes, it is supposed to fail. Is is by design that imports inside mixins are
visible only in the scope of the mixin. The explanation for that is that you do
not want to risk hijacking symbols. Take for example:

mixin template baz()
{
    import std.stdio : write;
    void func() { /* use write */}
}

void write
{
    /* log something */
}

struct B
{
    mixin baz;
    void foo()
    {
         write();   // oops, calls std.stdio.write
    }

}

Imagine that baz is written in a library and you don't know exactly what
imports it is using, so you expect that your user-defined function is called,
however, the symbol is hijacked by the import inside the mixin. This is
prevented by the current behavior where imports inside mixins are only visibile
in the scope of the mixin.

The current behavior is the correct one, so closing this as invalid.

--

Reply via email to