gracelang / minigrace

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

try-catch _exressions_ don't return a value. #142

Closed KimBruce closed 9 years ago

KimBruce commented 9 years ago

A try-catch expression always seems to return a value of type Done. See the following example:

method tryIt -> Number {
    try {
        5
    } catch {e: ProgrammingError ->
        4
    }
}

print (tryIt)

Executing this program gives an answer of done, when it should return 5. This is in contrast with both if-then-else and match statements which do return the appropriate value.

We can work around this by assigning the answer to a variable and then listing the variable as the last line of the method, but this should not be necessary.

[Note: We have not yet added exceptions to the static type checker so this is a run-time semantics issues]

apblack commented 9 years ago

Fixed in commit a9998f45ed59 in the JS backend. This is also fixed in the C backend, except that returns in the finally clause cause the runtime to crash because of mis-handled longjmp buffers.