grain icon indicating copy to clipboard operation
grain copied to clipboard

Compiler: Early return

Open ospencer opened this issue 3 years ago • 2 comments

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.

ospencer avatar Mar 09 '21 20:03 ospencer

Once this is completed, let's resolve this: https://github.com/grain-lang/grain/pull/540#discussion_r589965129

ospencer avatar Mar 09 '21 20:03 ospencer

We've made the decision that if a function is to use a return statement, 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

tqwewe avatar Sep 14 '22 18:09 tqwewe