digitalmars.D.bugs - [Issue 18587] New: Context pointer not set for delegate template
- d-bugmail puremagic.com (45/45) Mar 10 2018 https://issues.dlang.org/show_bug.cgi?id=18587
https://issues.dlang.org/show_bug.cgi?id=18587 Issue ID: 18587 Summary: Context pointer not set for delegate template parameter when declared in struct body Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: simen.kjaras gmail.com struct S { int n; R!(() => n) a; } struct R(alias fn) { int get() { return fn(); } } unittest { auto s = S(3); assert(s.a.get() == 3); } The above code fails with 'Error: need 'this' for 'n' of type 'int''. It is clear that the intended semantics of the above code is similar to this: struct S { int n; auto a() { return R!(() => n)(); } } struct R(alias fn) { int get() { return fn(); } } unittest { auto s = S(3); assert(s.a.get() == 3); } However, the latter example works, while the former doesn't. This leads to unnecessary boilerplate and unreadable code. --
Mar 10 2018