[Issue 24265] ref delegate literal no longer implicitly converts to unannotated type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 29 21:06:26 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24265
Paul Backus <snarwin+bugzilla at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|ref delegate no longer |ref delegate literal no
|implicitly converts to |longer implicitly converts
|unannotated type |to unannotated type
--- Comment #6 from Paul Backus <snarwin+bugzilla at gmail.com> ---
The bug *is* related to dropping function attributes during implicit
conversion, and it only affects a delegate whose type is inferred from the type
of a delegate literal:
---
void test()
{
int local;
auto inferred = delegate ref int() => local;
ref int fun() pure nothrow @nogc @safe;
static assert(is(typeof(inferred) == typeof(&fun)));
typeof(&fun) explicit = inferred;
ref int f();
typeof(&f) dg;
dg = &fun; // ok
dg = explicit; // ok
dg = inferred; // error
}
---
Output:
---
bug.d(17): Error: cannot implicitly convert expression `inferred` of type `int
delegate() pure nothrow @nogc ref @safe` to `int delegate() ref`
---
Somehow, the compiler is ending up with two internal representations of the
"same" delegate type, and only one of them can implicitly convert to the
unannotated version.
--
More information about the Digitalmars-d-bugs
mailing list