www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15248] New: Function in current module is not allowed to

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

          Issue ID: 15248
           Summary: Function in current module is not allowed to overload
                    imported function
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: samjnaa gmail.com

Using dmd 2.0.68.2, I try to compile the following simple function:

import std.math;
real round(real val, int prec)
{
    real pow = 10 ^^ prec;
    return round(val * pow) / pow;
}

Trying to compile this I get:

foo.d(5): Error: function foo.round (real val, int prec) is not callable using
argument types (real)

When I've imported std.math which contains round(real), the compiler should not
complain about not being able to call the overload function defined in *this*
module. I don't see anything in http://dlang.org/module.html that says I cannot
define an overload of an imported function. I was pointed to
http://dlang.org/hijack.html but even as per the rules there:

1. Perform overload resolution independently on each overload set
2. If there is no match in any overload set, then error
3. If there is a match in exactly one overload set, then go with that
4. If there is a match in more than one overload set, then error

Here there is only one round(real, int) i.e. in the current module and only one
round(real) i.e. in the imported module, so as per rule 3, there should be a
clear resolution. Clearly when the signature of the overload in the current
module is different from that in the imported module, there should be no
hijacking and thus no measures needed to prevent it. 

Thus the compiler should not error out. Yet I am not able to compile.

--
Oct 26 2015