Wondering about errors…

Jacob Carlborg doob at me.com
Tue May 28 02:24:41 PDT 2013


On 2013-05-27 22:32, Walter Bright wrote:

> 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.

Clang is still a lot better on this than DMD. Take this simple example:

void main ()
{
     int a = 3 // Missing semicolon, line 3
     int b = 5;
}

Compiling this with DMD gives the following error:

main.d(4): Error: semicolon expected, not 'int'

Where's Clang gives the following error for the same code:

main.c:3:11: error: expected ';' at end of declaration
         int a = 3
                  ^
                  ;
1 error generated.

It knows that you most likely meant to put the semicolon on the end of 
line 3 instead of the beginning of line 4. It also don't give completely 
false spell checking suggestion, like Adam showed:

Error: undefined identifier gf, did you mean template to(T)

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list