parser: Return statements must always have a value
Early returns in functions which do not return a value are current impossible, as the parser will always attempt to parse an expression after a return keyword.
How would we go about doing this?
function f(){
return
1+2
let x = 10
}
This is going to be parsed as "return 1+2" followed by "let x=10". So don't we need a way to determine the void return? I'm trying to say that while parsing return, we won't know when to end the return statement, which would have been possible if semicolons were mandatory. We can maybe do "return () " to indicate it's a return from a function that doesn't return anything. Just a suggestion
I think EOL (end of line) is supposed to terminate a statement. It would be intersting to discuss wether the void return should be handled as return with an expression of implicit type void or as a special case.
As a side note, this example would also be ambiguous without that rule of EOL termination ( return (1 + 3 - 1) or return 1 ?).
function f() -> i32 {
return 1
+3 - 1
let x = 10
}
I just checked, EOL is indeed terminating a statement. I got confused because of the example I gave. It was parsing the following line as an expression for return, which made me believe Eol didn't matter. But seeing the code for parsing expression it makes sense why that happened. Thanks. I'll try to make a pr for this issue
Seems to be fixed by https://github.com/SerenityOS/jakt/commit/c213b581ce544d2882d7b13a0e48ae40ad00aeb8