Improving Compiler Error Messages

Marianne Gagnon auria.mg at gmail.com
Sun May 2 18:46:21 PDT 2010


> 6. propagate error productions
> 
> [...]
> 
> This can be done in a compiler by replacing every production that produces an error with an error production (i.e. a NaN) and then propagate them. For example, for the expression:
> 
> z = x + y;
> 
>  if y is undefined, print the error message about y, then replace y in the syntax tree with:
> 
> z = x + _error_;


This is probably quite nice; I believe GCC does that. There is however one thing I don't like about the way GCC does that, and I'd like to raise it :

In GCC, let's say I have code above, with "z" being assigned type "error".
If my code contains :

foo(z);
bar(z);
foobar(x, y, z);

then GCC will spew something like :

error: no matching call for foo( type_error )
error: no matching call for bar( type_error )
error: no matching call for foobar( type_error )

I think that if you indeed have as goal to reduce useless cascading error messages, then it would be great to avoid that; I would tend to say it'd work to just plain ignore any line using "z" after that, or avoid checking the type of "z" if we know it's an error. That'd spare lots of useless error messages :)


More information about the Digitalmars-d mailing list