Bug 21545 – [dip1000] cannot assign ref returning delegate to variable with lower attributes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-01-13T21:37:07Z
Last change time
2024-12-13T19:14:01Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#19853 →

Comments

Comment #0 by qs.il.paperinik — 2021-01-13T21:37:07Z
Using -preview=dip1000, one cannot assign e.g. a pure delegate to a delegate type variable without pure annotation: void main() { int i; alias DG = ref int delegate() @safe; DG dg = delegate ref() @safe => i; } This errors on the assignment of DG. Without the preview switch, it compiles.
Comment #1 by ag0aep6g — 2021-01-13T22:25:18Z
Bizarre: void main() { int i; auto dg = delegate ref() @safe => i; alias DgFull = ref int delegate() pure nothrow @nogc @safe; alias DgAuto = typeof(dg); pragma(msg, DgFull); /* int delegate() pure nothrow @nogc ref @safe */ pragma(msg, DgAuto); /* int delegate() pure nothrow @nogc ref @safe */ pragma(msg, is(DgFull == DgAuto)); /* true; okay */ alias DgSafe = ref int delegate() @safe; pragma(msg, is(DgFull : DgSafe)); /* true; okay */ pragma(msg, is(DgAuto : DgSafe)); /* false; wat */ }
Comment #2 by ag0aep6g — 2021-01-13T22:59:45Z
(In reply to ag0aep6g from comment #1) > int i; > auto dg = delegate ref() @safe => i; > > alias DgFull = ref int delegate() pure nothrow @nogc @safe; > alias DgAuto = typeof(dg); > > pragma(msg, DgFull); /* int delegate() pure nothrow @nogc ref @safe */ > pragma(msg, DgAuto); /* int delegate() pure nothrow @nogc ref @safe */ > pragma(msg, is(DgFull == DgAuto)); /* true; okay */ `DgAuto` actually also has the attributes`scope` and `return`, but they have a special "inferred" marker. That means they're not printed.[1] Apparently, the marker also has an effect on `is(X == Y)`. Still bizarre. [1] https://github.com/dlang/dmd/blob/f341be3de711f9dbb91011e3650f8afc3818ec25/src/dmd/mtype.d#L7131-L7134
Comment #3 by robert.schadek — 2024-12-13T19:14:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19853 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB