diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-22 17:54:00 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-11-22 17:54:00 +0100 |
commit | 6c5ee537782970797700c99a79293b9590580817 (patch) | |
tree | fc008a5729efcb2fe0b5b2f168541120afede651 /tests/custom/00_syntax | |
parent | 8faa3059951a38bc9e6065470892d01a92fa785b (diff) |
compiler: ensure that arrow functions with block bodies return no value
Follow ES6 semantics and ensure that arrow functions with a block body
don't implicitly return the value of the last executed statement.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/00_syntax')
-rw-r--r-- | tests/custom/00_syntax/19_arrow_functions | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/custom/00_syntax/19_arrow_functions b/tests/custom/00_syntax/19_arrow_functions index 8dcce6c..761705b 100644 --- a/tests/custom/00_syntax/19_arrow_functions +++ b/tests/custom/00_syntax/19_arrow_functions @@ -38,7 +38,7 @@ test // parentheses may be omitted if arrow function takes only one argument test4_fn = a => { - a * 2; + return a * 2; }; // curly braces may be omitted if function body is a single expression @@ -122,3 +122,26 @@ In line 2, byte 10: (a + 1) => { print("test\n") } %} -- End -- + + +Arrow functions consisting of a single expression implicitly return the expression +results. Arrow functions having a statement block as body do not return any result +by default but may return explictly. + +-- Expect stdout -- +[ + 4, + null, + 4 +] +-- End -- + +-- Testcase -- +{% + printf("%.J\n", [ + (() => 2 * 2)(), + (() => { 2 * 2 })(), + (() => { return 2 * 2 })() + ]); +%} +-- End -- |