Bug 4058 – Wrong error message with __traits(getMember
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-04-03T12:01:00Z
Last change time
2013-01-01T19:44:47Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-04-03T12:01:17Z
struct Test {
void hello() {}
}
void main() {
Test t;
string m = "hello";
__traits(getMember, t, m)(); // line 7
}
dmd 2.042 gives:
test.d(7): Error: string expected as second argument of __traits getMember instead of m
test.d(7): Error: function expected before (), not false of type bool
Defining m as const,immutable or enum string avoids this error. So those two error messages are bad. Something better can be:
test.d(7): Error: the second argument of __traits getMember must be a not mutable string.
Comment #1 by andrej.mitrovich — 2012-10-20T08:48:55Z
It now gives this generic error first:
test.d(7): Error: variable m cannot be read at compile time
I think that's clearer now.
Comment #2 by bearophile_hugs — 2013-01-01T19:44:47Z
Now this code:
struct Test {
void hello() {}
}
void main() {
Test t;
string m = "hello";
auto x = __traits(getMember, t, m); // line 7
}
Prints:
test2.d(7): Error: variable m cannot be read at compile time
test2.d(7): Error: string expected as second argument of __traits getMember instead of m
I think the second error message should be inhibited, but this situation is acceptable.