www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20912] New: Compiler incorrectly lists non-matching overloads

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

          Issue ID: 20912
           Summary: Compiler incorrectly lists non-matching overloads as
                    matching in diagnostic
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrej.mitrovich gmail.com

-----
struct Struct
{
    int get() { return 1; }
}

public T execute (T)(T function(ref Struct)  safe dg)
{
    Struct rng;
    return dg(rng);
}

public T execute (T)(T delegate(ref Struct)  safe dg)
{
    Struct rng;
    return dg(rng);
}

void main (string[] args)
{
    execute((ref Struct rng) { return rng.get(); });
}
-----

$ dmd test.d
test.d(20): Error: test.execute called with argument types (int function(ref
Struct rng)  system) matches both:
test.d(6):     test.execute!int.execute(int function(ref Struct)  safe dg)
and:
test.d(12):     test.execute!int.execute(int delegate(ref Struct)  safe dg)


This is wrong. The call doesn't match either of those calls, that is the actual
error here. Because it tries to call `rng.get()` which is an unsafe function.

--
Jun 08 2020