1
0
mirror of https://github.com/janet-lang/janet synced 2025-09-06 04:48:03 +00:00

Address compiler bug with break.

Using result from `break` expression could trigger code that would
work, yet contain invalid, dead code preventing good marshalling.
This commit is contained in:
Calvin Rose
2023-09-28 20:14:22 -05:00
parent b63d41102e
commit e05bc7eb54
3 changed files with 28 additions and 7 deletions

View File

@@ -924,4 +924,25 @@
[:strict 3 4 "bar-oops"]])
"maclintf 2")
# Bad bytecode wrt. using result from break expression
(defn bytecode-roundtrip
[f]
(assert-no-error "bytecode round-trip" (unmarshal (marshal f make-image-dict))))
(defn case-1 [&] (def x (break 1)))
(bytecode-roundtrip case-1)
(defn foo [&])
(defn case-2 [&]
(foo (break (foo)))
(foo))
(bytecode-roundtrip case-2)
(defn case-3 [&]
(def x (break (do (foo)))))
(bytecode-roundtrip case-3)
# Debug bytecode of these functions
# (pp (disasm case-1))
# (pp (disasm case-2))
# (pp (disasm case-3))
(end-suite)