digitalmars.D - Re: Improving Compiler Error Messages
- Marianne Gagnon <auria.mg gmail.com> May 02 2010
- Walter Bright <newshound1 digitalmars.com> May 02 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 :)
May 02 2010
Marianne Gagnon wrote: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 :)
You're right, gcc has an incomplete implementation of this. The idea is that there will be no further error messages if any part of those messages would contain the "error" production. dmd partially does that, and it's definitely the direction we want to push it.
May 02 2010