gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Missing operator in `then` clause not detected #314

Closed apblack closed 4 years ago

apblack commented 4 years ago

The errormessages module of the compiler contained a method readableStringFrom(xs:Collection) using (connectingWord:String) with the following code:

    if (count == 1) then {
        if (xs.size > 2) then { result := result ++ "," }
        result := result ++ " " connectingWord ++ " "
    } elseif {
        ...

Notice that there is a missing ++ operator between " " and connectingWord.

This should be detected as a syntax error, but is not. Instead it is treated as two statements

        result := result ++ " "
        connectingWord ++ " "

the second of which causes the then branch to return a value (which is ignored), but does nothing. The same syntax error in other contexts, such as block bodies and else branches, correctly raises a syntax error.

The root cause is that special-purpose code is being used to parse if(_)then(_)else(_).

apblack commented 4 years ago

This is fixed in commit b2e4f49, and a test is added for this specific case.