forked from Mirror/wren
Fix returning from constructors (#845)
* Fix returning from constructors 1. Do not allow returning with a value 2. Return the instance, correctly, even when the user returned explicitly * revise error message for consistency, revise implementation details a bit, fix extra args to finishBody * clarify tests a bit * document constructor return Co-authored-by: ruby0x1 <ruby0x1@pm.me>
This commit is contained in:
committed by
GitHub
parent
68f5c096d8
commit
041f1bab8d
5
test/language/constructor/cannot_return_value.wren
Normal file
5
test/language/constructor/cannot_return_value.wren
Normal file
@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {
|
||||
return 1 // expect error
|
||||
}
|
||||
}
|
||||
18
test/language/constructor/return_without_value.wren
Normal file
18
test/language/constructor/return_without_value.wren
Normal file
@ -0,0 +1,18 @@
|
||||
class Baz {
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
class Bar {
|
||||
construct new() {
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
construct new() {
|
||||
return
|
||||
}
|
||||
}
|
||||
System.print(Baz.new()) // expect: instance of Baz
|
||||
System.print(Bar.new()) // expect: instance of Bar
|
||||
System.print(Foo.new()) // expect: instance of Foo
|
||||
System.print(Foo.new() != null) // expect: true
|
||||
Reference in New Issue
Block a user