Appearance
Go calls with several results that can panic, and named results
Status: accepted · Date: 2026-11-29
The record on several results refused a, b := f() when f can panic, and named results. This record says how the proved path accepts both.
The decision
a, b := f()anda, b = f()withfable to panic become a bind of the call to the first name on the left that is not_, then aletTupleof all the names from that bound tuple. The tuple's name is one of the names that theletTuplebinds, so it shadows the tuple and every lookup after the statement sees what the interpreter's locals hold. The proof shows this with a lemma: a binding under another binding of the same name changes no lookup.pushes_simandsets_simtake the rest of the body in any locals whose lookups equal the expected ones, not only in the same list. The tuple's extra binding needs this.return f()of such a call already went through the bind of the panicking-calls record.- A named result is a local that starts at its zero value (Go specification, "Return statements"). The interpreter's
funcOfand the translator both putvar r Tfor each named result in front of the body, so the existing proof ofvarcovers them.
What is left out
- A bare
returnwith named results. The interpreter would have to read the result locals at each return, and the IRreturntakes a value. _, _ = f()whenfcan panic: no name on the left takes the tuple.- A call with several results that can panic inside a counted loop's body, as for every assignment of several values there.
Testing
tests/go/Multi.lean checks both sides on panicking callees and named results. The differential test now calls functions with several results that can panic, outside loops, and checks them against go run.
This page is docs/decisions/2026-11-29-go-panicking-tuple-calls.md at commit 5f1d031.
