Wondering about errors…

Walter Bright newshound2 at digitalmars.com
Mon May 27 13:32:46 PDT 2013


On 5/27/2013 4:32 AM, Russel Winder wrote:
> Using rdmd, it appears that the first error in the code can lead the
> parsing and template handling of everything following to be wrong. I
> keep finding that I am getting spurious errors about things nothing to
> do with the actual error, that simply go away when the real error is
> fixed. This would imply that most errors reported are generally
> spurious?

The usual approach to handling errors in a compiler is to guess at what the user 
actually meant, repair the AST according to that guess, then continue on. 
Unfortunately, the guess is usually wrong and the result is cascaded errors, of 
which only the first is meaningful.

DMD has been gradually switching over to a more novel approach, one that I 
haven't seen elsewhere. Once an error is discovered, the AST is marked as 
"erroneous". That erroneous state propagates upwards to the root of the AST, and 
that any AST that relies on an erroneous AST is itself erroneous, and no further 
error messages are emitted for it.

The result should be that only "original sin" errors are reported.

This has already resulted in a great reduction of spurious error messages, but 
clearly we have more work to do.



More information about the Digitalmars-d mailing list