Bug 20040 – dip1000 implicit delegate attribute stripping fails

Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-07-10T19:31:43Z
Last change time
2022-08-11T07:32:41Z
Keywords
safe
Assigned to
No Owner
Creator
thomas.bockman

Comments

Comment #0 by thomas.bockman — 2019-07-10T19:31:43Z
struct A { void method() pure @safe nothrow @nogc { } } void test(scope void delegate() del) @safe { } void main() @safe { A a; // OK: void delegate() del = &a.method; /* onlineapp.d(19): Error: function onlineapp.test(scope void delegate() del) is not callable using argument types (void delegate() pure nothrow @nogc @safe) onlineapp.d(19): cannot pass argument &a.method of type void delegate() pure nothrow @nogc @safe to parameter scope void delegate() del */ test(&a.method); } The above code works fine - as, I believe, it should - unless I compile with -preview=dip1000 . This issue breaks some of my toString() implementations, so a fix would be appreciated...
Comment #1 by bugzilla — 2019-12-19T08:07:44Z
The following will work: struct A { int* p; void method() scope pure @safe nothrow @nogc { } } void test(scope void delegate() del) @safe { } void main() @safe { A a; test(&a.method); } Note the two additions: 1. `scope` to method(), which says that the method won't escape `this.p` 2. `int* p;` because otherwise the `scope` added will be ignored A possible fix to the compiler would be to have the address of a method be implicitly marked `scope` if none of the fields have any indirections.
Comment #2 by bugzilla — 2022-08-11T07:32:41Z
This is working in master.