grain
grain copied to clipboard
Compiler: Early return
This would add the ability to return early from a function. We've made the decision that if a function is to use a return statement, then all implicit returns must be made explicit. The user should see an error that looks something like this:
325. someFunctionThatHasReturnType()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
326. }
An explicit `return` statement is required when a function returns early.
Once this is completed, let's resolve this: https://github.com/grain-lang/grain/pull/540#discussion_r589965129
We've made the decision that if a function is to use a
returnstatement, then all implicit returns must be made explicit.
Is there any discussion I can read about this? I don't see this being much benefit. Coming from Rust, having the last line not need return feels quite natural, regardless of whether previous lines had an early return