[Issue 20912] New: Compiler incorrectly lists non-matching overloads as matching in diagnostic

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 9 03:48:05 UTC 2020


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 at puremagic.com
          Reporter: andrej.mitrovich at 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.

--


More information about the Digitalmars-d-bugs mailing list