Bug 5877 – Cannot treat '__traits(parent, obj)' as a type
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-23T23:13:00Z
Last change time
2012-12-10T15:42:43Z
Keywords
rejects-valid
Assigned to
nobody
Creator
kennytm
Comments
Comment #0 by kennytm — 2011-04-23T23:13:49Z
Since the introduction of __traits(parent) in commit 2e261cd6, it is possible that the __traits expression returns a type. However, the parser does not recognize this in an alias statement, and rejects the code.
--------------------------------------------------------
class B {
int x();
alias __traits(parent, x) S;
static assert(is(B == S));
}
--------------------------------------------------------
x.d(3): basic type expected, not __traits
x.d(3): no identifier for declarator int
x.d(3): semicolon expected to close alias declaration
x.d(3): Declaration expected, not '__traits'
--------------------------------------------------------
A workaround is to create an existing expression that returns a type:
--------------------------------------------------------
class B {
int x();
alias typeof(__traits(parent, x).init) S;
static assert(is(B == S));
}
--------------------------------------------------------
But it is better the __traits work without these hacks.
Comment #1 by kennytm — 2011-04-24T01:08:14Z
The same applies anywhere that expects a type, e.g.
template (alias m, T = __traits(parent, m)) {
// ^^^^^^^^^^^^^^^^^^^
__traits(parent, m) s;
// ^^^^^^^^^^^^^^^^^^^
etc.
Comment #2 by andrej.mitrovich — 2012-12-10T15:42:43Z
*** This issue has been marked as a duplicate of issue 7804 ***