The Clang front-end of LLVM tries harder to give good error messages: http://clang.llvm.org/diagnostics.html One simple but nice feature of its error messages is the usage of "aka", this is an example: t.c:13:9: error: member reference base type 'pid_t' (aka 'int') is not a structure or union This is a wrong D2 program: void main() { alias int Foo; Foo f; f = f.x; } DMD 2.049 prints: test.d(4): Error: no property 'x' for type 'int' But a more useful error message can be: test.d(4): Error: no property 'x' for type 'Foo' (aka 'int')
That's a really nice idea! Also see bug 4917.
Trying to improve the bug report title, if you don't mind...
Another comment about it: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=120492
(In reply to comment #0) > The Clang front-end of LLVM tries harder to give good error messages: > http://clang.llvm.org/diagnostics.html > > One simple but nice feature of its error messages is the usage of "aka", this > is an example: > > t.c:13:9: error: member reference base type 'pid_t' (aka 'int') is not a > structure or union > > > This is a wrong D2 program: > > > void main() { > alias int Foo; > Foo f; > f = f.x; > } > > > DMD 2.049 prints: > test.d(4): Error: no property 'x' for type 'int' > > But a more useful error message can be: > test.d(4): Error: no property 'x' for type 'Foo' (aka 'int') Agreed, would be very nive. Have no idea at which stage in the "decoding" sequence name aliases are resoved, which certainly determines the difficulty of implementing the feature. Anyway, since D's term is 'alias', this term should be used in error messages instead of 'aka'. Also, 'aka' can be difficult for non-english speakers (have learnt it myself only recently, after decades of English practice). 'alias' does not have this issue due to beeing part of D's terminology. However, it goes in opposite sense, I guess: test.d(4): Error: no property 'x' for type 'Foo' (alias for 'int') Or maybe suppleness of English allows the following to be clear? test.d(4): Error: no property 'x' for type 'Foo' ('int' alias) Denis
Another similar example of bad error message, DMD 2.054: enum Foo { A } void main() { auto x = Foo.B; } test.d(3): Error: no property 'B' for type 'int'
GCC too uses "aka" in error messages: #include <stdint.h> struct S { int16_t x; }; int main(int argc, char **argv) { S s = { argc }; return 0; } ...>g++ -std=c++0x temp.cpp -o temp temp.cpp: In function 'int main(int, char**)': temp.cpp:4:18: error: narrowing conversion of 'argc' from 'int' to 'int16_t {aka short int}' inside { } [-fpermissive]
Maybe related to issue 6916
This wrong D2 code: T foo(T)(T[] x) { return T[0]; } void main() { foo([1, 2, 3]); } With DMD 2.059head gives: test.d(1): Error: int must be an array or pointer type, not int test.d(3): Error: template instance test.foo!(int) error instantiating But a more readable first error message is like: test.d(1): Error: T (aka 'int') must be an array or pointer type, not int
One case: alias ushort UT; void main() { int x; UT y = x; } DMD 2.060alpha gives: test.d(4): Error: cannot implicitly convert expression (x) of type int to ushort But a more useful error message is similar to: test.d(4): Error: cannot implicitly convert expression (x) of type int to UT (alias for ushort) See also Issue 8044