[Issue 15179] Local imports cause outer imports to be excluded from overload set

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Mar 22 16:13:56 PDT 2016


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

Jesse Phillips <Jesse.K.Phillips+D at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Jesse.K.Phillips+D at gmail.co
                   |                            |m

--- Comment #4 from Jesse Phillips <Jesse.K.Phillips+D at gmail.com> ---
(In reply to Walter Bright from comment #3)
> Probably not going to change the import lookup rules for this case.

Consider:

Module bar provides a function, foobar, that takes an int.

----------
module bar;

bool foobar(int i) {
    return true;
}
----------

Module foo defines foobar to take a string.

----------
module foo;

bool foobar(string m) {
    return false;
}
----------

Main calls bar.foobar and the assertion passes.

----------
import bar;

void main() {
import foo;
    assert(7.foobar);
}
----------


Module foo is modified, it now defines a function, foobar, that takes an int.

----------
module foo;

bool foobar(string m) {
    return false;
}

/// Highjack call to bar.foobar
bool foobar(int m) {
    return false;
}
----------

The assertion will now fail in main due to function highjacking (no compiler
error):

$  rdmd test.d .\foo.d .\bar.d

core.exception.AssertError at test.d(5): Assertion failure

--


More information about the Digitalmars-d-bugs mailing list