diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-23 13:46:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-23 13:46:44 +0100 |
commit | 11adbbe2ce11b1ee906d48ac6c174fa1147a5b32 (patch) | |
tree | fc008a5729efcb2fe0b5b2f168541120afede651 /tests | |
parent | 8faa3059951a38bc9e6065470892d01a92fa785b (diff) | |
parent | 6c5ee537782970797700c99a79293b9590580817 (diff) |
Merge pull request #125 from jow-/arrow-functions-blocks-no-return
compiler: ensure that arrow functions with block bodies return no value
Diffstat (limited to 'tests')
-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 -- |