Bug 17694 – traits compiles fails for property of property
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-26T12:27:00Z
Last change time
2017-07-26T12:51:03Z
Assigned to
nobody
Creator
andre
Comments
Comment #0 by andre — 2017-07-26T12:27:59Z
While the first assertion works, the second assertion fails.
I expect it should work, as the statement "typeof(TButton.Margins.Left) l;" works fine
class TButton
{
@property TBounds Margins() { return null; }
}
class TBounds
{
@property float Left() { return 0.0; }
}
void main()
{
mixin(`static assert(__traits(compiles, TButton.Margins));`); // OK
mixin(`static assert(__traits(compiles, TButton.Margins.Left));`); // FAILS
}
Comment #1 by schveiguy — 2017-07-26T12:51:03Z
Actually, the issue is that the thing you are checking isn't valid syntax.
For example:
TBounds.Margins.Left;
Error: need 'this' for 'Margins' of type '@property TBounds()'
What you need is either the typeof, or to use an instance instead of the type itself:
mixin(`static assert(__traits(compiles, TButton.init.Margins.Left));`);
mixin(`static assert(__traits(compiles, typeof(TButton.Margins.Left)));`);