diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-10-02 20:53:39 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-10-04 21:14:31 +0200 |
commit | 7bbba788dba3a5cd2339b81d8a62761e6dc83b7e (patch) | |
tree | dd781b5d8b04c7929229f1915730cb2b65c92621 /tests | |
parent | a45f2a388efb649e0373a45c6db1d009dc18072d (diff) |
compiler: optimize function return opcode generation
Track last emitted statement type in compiled code and only generate final
`return null` opcodes if there is no preceeding `return` statement.
Also use this statement tracking to avoid emitting invalid return opcodes
for arrow function bodies with trailing empty statements.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/custom/99_bugs/41_compiler_invalid_return_opcode | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/custom/99_bugs/41_compiler_invalid_return_opcode b/tests/custom/99_bugs/41_compiler_invalid_return_opcode new file mode 100644 index 0000000..a97dae9 --- /dev/null +++ b/tests/custom/99_bugs/41_compiler_invalid_return_opcode @@ -0,0 +1,20 @@ +When compiling an arrow function body with a trailing loop or conditional +statement having an empty body, the emitted return code incorrectly +overwrote the target address of the jump instruction. + +-- Testcase -- +(() => { + if(0) + ; +})(); + +print("OK\n"); +-- End -- + +-- Args -- +-R +-- End -- + +-- Expect stdout -- +OK +-- End -- |