1
0
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:
Chayim Refael Friedman
2021-04-08 08:53:05 +03:00
committed by GitHub
parent 68f5c096d8
commit 041f1bab8d
4 changed files with 59 additions and 8 deletions

View File

@ -0,0 +1,5 @@
class Foo {
construct new() {
return 1 // expect error
}
}

View 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