Error message improvement ideas

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 18 10:55:29 PST 2015


I really want the compiler to be more specific about what worked 
and what didn't in error messages. Check this out.

---
void foo(int a, string b) {}
void foo(string b) {}

void main() {
	foo(10.2, "foo");
}
---

k.d(5): Error: None of the overloads of 'foo' are callable using 
argument types (double, string), candidates are:
k.d(1):        k.foo(int a, string b)
k.d(2):        k.foo(string b)


A relevant piece is (double, string), what I passed to it, but it 
is kinda mixed into the rest of the line. Moreover, what one 
didn't match?

We already highlight the word "Error:". I propose we also 
highlight stuff in the details lines, like this (pretending the 
color tags actually came through)

k.d(1):        k.foo(<red>int</red> a, <green>string</green> b)
k.d(2):        k.foo(<red>string</red> b)


The first arg I passed never fit the first arg of the options, 
they get red color. My string did pass one though, so it gets 
green to highlight a partial match.



Doing this on template constraints too (along with formatting 
them with some whitespace) would be huge toward making those 
std.algorithm errors be readable as well.



Moreover, I wouldn't mind if the compiler had an error output 
format that could spit out xml or something for computer 
consumption, with the same level of detail (if not more). If I 
were overhauling it all, I'd make all error messages inside the 
compiler be marked up to the max, then the top layer prints them 
appropriately for the device it is talking to (so disabling color 
on pipes, pretty printing for users, etc)


But the specifics aren't as important as having the compiler just 
somehow make it obvious at a glance what worked and what didn't. 
It could also do:

k.d(1):        k.foo(int a, string b)
                      ^^^    ++++++
k.d(2):        k.foo(string b)
                      ^^^^^^

or whatever instead of (or addition to, let's not forget a lot of 
people can't see color and the contrast on terminals may be quite 
poor) color.


More information about the Digitalmars-d mailing list