[Issue 17239] New: template this in typeof expressions
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Mar 2 04:29:26 PST 2017
https://issues.dlang.org/show_bug.cgi?id=17239
Issue ID: 17239
Summary: template this in typeof expressions
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: john.loughran.colvin at gmail.com
struct S
{
int a;
int b() { return a; }
@property int b(this X)() { return 2; }
}
pragma(msg, typeof(S.a)); // int
pragma(msg, typeof(S.b)); // int
pragma(msg, typeof(S.c)); // void
None of the expressions in the above typeofs can actually compile for real
(need `this` reference for `a`). However, the top two seem to be allowed but
the bottom isn't.
The makes it very painful to implement forwarding transparently (e.g.
std.typecons.Proxy / Typedef) because if you template on `this` in order to
handle shared/immutable/const then typeof expressions that worked for the
original type won't work for the wrapped type. This leaves you with method
duplication (x4: mutable, const, shared, shared const) as the only option.
--
More information about the Digitalmars-d-bugs
mailing list