www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20226] New: selective import in function scope fails to merge

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

          Issue ID: 20226
           Summary: selective import in function scope fails to merge
                    overload sets
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

unittest {
    import std.complex : abs;
    import std.math : abs;
    //  template std.complex.abs cannot deduce function
    // from argument types !()(int)
    auto a = abs(1);
}

Changing the order of imports above makes the code compile.

Using regular imports correctly merges overload sets:

unittest {
    import std.complex;
    import std.math;
    auto a = abs(1);
}

This is likely related to the restrictions on overload sets in function scopes:

unittest {
    void fun() {}
    void fun(int i) {} // declaration fun is already defined
}

--
Sep 18 2019