-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return statements inside object constructors behave inconsistently #325
Comments
Is there any reason to permit `return` directly inside an object constructor?
Andrew
… On Feb 17, 2020, at 20:08, IsaacOscar ***@***.***> wrote:
Consider the following four methods:
method foo1 {
object { return "Hello" }
"Goodbye" }
method foo2 {
object { {return "Hello"}.apply }
"Goodbye" }
method foo3 {
object { return "Hello" }}
method foo4 {
object { {return "Hello"}.apply }}
I would expect all 4 methods to return "Hello" when called, however this is not the case:
print(foo1) // prints "Goodbye"
print(foo2) // prints "hello"
print(foo3) // prints "a foo3"
print(foo4) // crashes with:
// RequestError: error on line 18 of module test: undefined
// 17: print(foo3)
// 18: print(foo4)
// minigrace: program test exited with code 3.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Hmm good point, all the examples I can think of involve putting a return inside a block (e.g. In the same vain there's no real reason to support returns directly within methods, e.g.
You could just delete the Really, there only use is inside blocks. |
If we allow
then it is hard to know (statically) the shape of the object returned from a class. I suppose that we could check that the I would be inclined to say that either:
Either way, a compiler has to detect such a return statement. |
Consider the following four methods:
I would expect all 4 methods to return "Hello" when called, however this is not the case:
The text was updated successfully, but these errors were encountered: