September 30, 2020 [Issue 21285] New: Delegate covariance broken | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21285 Issue ID: 21285 Summary: Delegate covariance broken Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: regression Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: hsteoh@quickfur.ath.cx Reduced code: -------- void main() { string path; int bank; auto aa = [ "path": (string arg) { path = arg; }, "bank": (string arg) { bank = 1; throw new Exception(""); }, ]; } -------- DMD 2.094 output: -------- /tmp/test.d(6): Error: cannot implicitly convert expression __lambda1 of type void delegate(string arg) pure nothrow @nogc @safe to void delegate(string) pure @safe -------- Surely `void delegate(string) pure nothrow @nogc @safe` is implicitly convertible to `void delegate(string) pure @safe`? Since nothrow is covariant to (implicit) throwing, and @nogc is covariant to (implicit) allocating. In any case, it's a bug that the compiler is unable to find a common value type for the above AA literal, since the common type `void delegate(string)` exists and works for both cases. Note that the same problem persists even if the AA's type is explicitly spelled out `void delegate(string)[string]`, so this is not directly related to type deduction of the AA, but rather is a failure to find a common type between the two values of the AA literal. This code successfully compiled with DMD 2.092, so this represents a recent regression. -- |
Copyright © 1999-2021 by the D Language Foundation