Skip to content

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() and a, b = f() with f able to panic become a bind of the call to the first name on the left that is not _, then a letTuple of all the names from that bound tuple. The tuple's name is one of the names that the letTuple binds, 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_sim and sets_sim take 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 funcOf and the translator both put var r T for each named result in front of the body, so the existing proof of var covers them.

What is left out ​

  • A bare return with named results. The interpreter would have to read the result locals at each return, and the IR return takes a value.
  • _, _ = f() when f can 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.