Appearance
Go: the order of checks around calls and len
Status: accepted · Date: 2026-11-30
The differential test (seed 589164818, on the CI of #329) found a function whose translation panicked with index out of range [1] with length 0 where Go panicked with index out of range [3] with length 0. The statement was if v := int64(("é" + s[1])[len(s[3])]); … with s empty.
Go's rule
The Go specification ("Order of evaluation") fixes the order of function calls, method calls, receive operations and binary logical operations, and leaves the rest unspecified. gc evaluates the calls of an expression, and len (and cap and append) of anything but a name, before its other operands, left to right, and does the same inside their arguments. Checked on go1.26:
s[1][len(s[3])],t[1] + len(s[3]),t[1] + g(0, t[3])and1/z + len(s[3])panic on the check inside the argument.s[1] + s[3],len(s[1]) + len(s[3])and(x + s[1])[t[3]]panic left to right. String concatenation and conversions are not moved.
The interpreter and the output test the checks left to right.
The decision
Pure.orderKnown accepts a statement's expression when it has no index check, so any order gives the same panic, or when, in each part, the checks are either all inside the arguments of calls, len and append, or all outside them. gc's order is then the interpreter's. translateStmtExpr and translateTopArgs apply it to the expression of every statement and to the arguments of a bound call. Values a, b keep checkedOnce, which allows at most one check.
translate_sound is unchanged: the translator only refuses more, and the proof takes the expression's translation from the new wrappers through translateStmtExpr_ok and translateTopArgs_ok.
Refused
A statement that mixes an index check inside such an argument with a check outside one, such as s[1][len(s[3])], xs[0] + len(t[0]) or a / b + len(t[i]). Modelling gc's order in the interpreter instead would tie the semantics to one compiler's choice in an area the specification leaves open.
The differential generator no longer divides or indexes inside the arguments of a call or of len. tests/go/EvalOrder.lean holds the regression.
This page is docs/decisions/2026-11-30-go-check-order.md at commit 5f1d031.
