Wintermute 0.3.3 — switch
Third step of the 0.3.x transpiler-language line: the tagged expression
switch. Alongside if, Go's other value-branching form now maps to an
Erlang case, and a pre-existing integer-literal mis-transpile is closed.
-
Tagged
switch→ Erlangcase-on-value — the expression-switch form,
mirroringemitIf:func Name(N int) string { switch N { case 1: return "one" case 2: return "two" default: return "many" } }
→
name(N) -> case N of 1 -> "one"; 2 -> "two"; _ -> "many" end.
Single literal case values; a
defaultis required and always emitted as the
catch-all_, sorted LAST regardless of its position in the Go source. Each
clause body runs in its own binding scope (boundsnapshotted and restored),
so the switch tag and sibling clauses obey the same outer-collision rejection
asifbranches and receive-pattern fields. Empty clauses are rejected; the
switch must be terminal and in tail position. An exhaustive switch (a
default whose every clause returns) also counts as terminating, so it may
serve as the then-branch of a bareif, exactly like an if/else. A type
switch (switch v := x.(type)) is rejected outright. -
Integer-literal normalization — every Go integer literal is now
normalized to decimal Erlang (strconv.ParseInt(v, 0, 64)+ base-10 format).
Previously the literal was emitted verbatim:0777produced Erlang0777
(read as 777 — a clean compile with the WRONG value) and0x1Fproduced
invalid Erlang. This was a pre-existing root cause affecting any octal/hex/
binary literal,return 0x1Fincluded. Overflow is a positioned error, never
a silent wrap.
Correctness is proven end-to-end by a real-toolchain rung: a switch
classifier fixture transpiles, compiles with erlc, and runs to a checked
result (classify:name(2) = "two").
Deliberately deferred to 0.3.4+ (all still error): switch without default,
multi-value cases (case 1, 2:), tagless switch, type switch, fallthrough,
and switch with an init statement.
Built subagent-driven and TDD: three tasks (fresh implementer + two-stage
review each), with the integer-literal fix promoted from a Task-1 review
Critical and a whole-branch opus review returning "ready to merge" after
folding two coverage tests (string case value, receive-field switch tag).