Issue 5004 - show both resolved symbols and original identifier in error messages involving aliases
Summary: show both resolved symbols and original identifier in error messages involvin...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2010-10-06 12:20 UTC by bearophile_hugs
Modified: 2022-12-17 10:42 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-10-06 12:20:15 UTC
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')
Comment 1 nfxjfg 2010-10-06 20:55:51 UTC
That's a really nice idea!
Also see bug 4917.
Comment 2 nfxjfg 2010-10-06 20:57:43 UTC
Trying to improve the bug report title, if you don't mind...
Comment 3 bearophile_hugs 2010-10-26 13:36:16 UTC
Another comment about it:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=120492
Comment 4 Denis Derman 2011-02-15 14:40:59 UTC
(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
Comment 5 bearophile_hugs 2011-07-18 01:42:25 UTC
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'
Comment 6 bearophile_hugs 2011-09-18 11:14:04 UTC
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]
Comment 7 bearophile_hugs 2011-11-15 23:53:47 UTC
Maybe related to issue 6916
Comment 8 bearophile_hugs 2012-03-20 17:10:41 UTC
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
Comment 9 bearophile_hugs 2012-05-06 06:52:35 UTC
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