Appearance
Go: errors on the proved path
Status: accepted · Date: 2026-12-05
Until now only the unproved translator handled Go's error. This record adds error values to the proved path. Go's error keeps its existing model in tolean/Go/Spec/Basic.lean, Option GoError, which records how an error was made.
The decision
- The interpreter (
tolean/Go/Spec/Eval.lean) has a valueerr ewithe : Go.error.niliserr nonewhere an error goes. The zero value oferrorisnil. errors.New(s)givesGo.errorsNew s.fmt.Errorf(f, e)givesGo.errorf ewhenfis a string literal that starts with%wand holds no other%. The rest of the message is not modeled. The interpreter and the translator take these calls only when the file imports the package and no local variable hides its name (Eval.pkgCall). A method call on a nameerrorsorfmtthat is not such a call is refused.e == nilande != nil, withnilon either side, becomeGo.isNil eand its negation.eqValgives a result only when one side isnil.- The translator types
errorasTy.error, printed asGo.error, unless the package declares the nameerror.
What stays refused
A package imported from a path other than exactly
errorsorfmt, even when its name iserrorsorfmt, as inexample.com/errors: itsNewcan returnnil.Eval.importsOfkeeps the complete path, and only the standard library paths give the calls their meaning. A package reads all its files together, so when any file binds the name to another path, even through an alias, no file gets the meaning. An import without an alias binds the name of the imported package clause, not the last part of its path:example.com/custommay saypackage errors. The translator does not read that clause, so any import without an alias outsideknownStdPathstakes the meaning away from every call oferrorsandfmtin the package.An expression that mixes a check inside the argument of
errors.Neworfmt.Errorfwith a check outside it, such as(xs[1] == 0) == (errors.New(ss[2]) == nil): Go evaluates the call's arguments first and panics at index 2, while the interpreter goes left to right.orderScopetreats the constructors as calls, as it does forlen. The differential test runs both forms in Go and checks the refusal.Comparing two errors that are not
nil. Go compares interface values by their dynamic type and value, so twoerrors.New("a")calls give different errors. The model does not record identity, so the interpreter has no result, and the translator refuses the comparison.Package-level sentinels such as
var ErrX = errors.New("x"), for the same reason: their use is to be compared by identity.errors.Is,errors.As,errors.Unwrap,e.Error()and every other function oferrorsandfmt, other formats offmt.Errorf, and a format that is not a literal.An
errorin a struct field or a slice element.
This page is docs/decisions/2026-12-05-go-errors.md at commit 5f1d031.
