feat: unify block, function, and method body parsing to support single-expression implicit returns
Refactor `finishBlock` in `wren_compiler.c` to detect single-expression bodies (no newline after `{`) and leave a value on the stack, enabling implicit returns for methods and functions. Add `finishBody` wrapper to handle constructor flag. Update all benchmark and test `.wren` files to remove explicit `return` keywords from getters and single-expression methods, relying on the new implicit return behavior. Remove old `return_null_if_brace.wren` test, add `newline_body.wren`, `newline_in_expression_block.wren`, and `no_newline_before_close.wren` tests for edge cases.
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
class Foo {
|
||||
getClosure {
|
||||
return new Fn { toString }
|
||||
}
|
||||
|
||||
toString { return "Foo" }
|
||||
getClosure { new Fn { toString } }
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
var closure = (new Foo).getClosure
|
||||
|
||||
@@ -9,14 +9,14 @@ class Outer {
|
||||
method {
|
||||
IO.print(this) // expect: Inner
|
||||
}
|
||||
toString { return "Inner" }
|
||||
toString { "Inner" }
|
||||
}
|
||||
|
||||
(new Inner).method
|
||||
}.call
|
||||
}
|
||||
|
||||
toString { return "Outer" }
|
||||
toString { "Outer" }
|
||||
}
|
||||
|
||||
(new Outer).method
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
class Foo {
|
||||
getClosure {
|
||||
return new Fn {
|
||||
return new Fn {
|
||||
return new Fn {
|
||||
return toString
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toString { return "Foo" }
|
||||
getClosure { new Fn { new Fn { new Fn { toString } } } }
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
var closure = (new Foo).getClosure
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Foo {
|
||||
bar { return this }
|
||||
baz { return "baz" }
|
||||
bar { this }
|
||||
baz { "baz" }
|
||||
}
|
||||
|
||||
IO.print((new Foo).bar.baz) // expect: baz
|
||||
|
||||
@@ -4,7 +4,7 @@ class Foo {
|
||||
IO.print(this.bar) // expect: bar
|
||||
}
|
||||
|
||||
static bar { return "bar" }
|
||||
static bar { "bar" }
|
||||
}
|
||||
|
||||
Foo.test
|
||||
|
||||
Reference in New Issue
Block a user