Skip to content

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 value err e with e : Go.error. nil is err none where an error goes. The zero value of error is nil.
  • errors.New(s) gives Go.errorsNew s. fmt.Errorf(f, e) gives Go.errorf e when f is a string literal that starts with %w and 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 name errors or fmt that is not such a call is refused.
  • e == nil and e != nil, with nil on either side, become Go.isNil e and its negation. eqVal gives a result only when one side is nil.
  • The translator types error as Ty.error, printed as Go.error, unless the package declares the name error.

What stays refused ​

  • A package imported from a path other than exactly errors or fmt, even when its name is errors or fmt, as in example.com/errors: its New can return nil. Eval.importsOf keeps 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/custom may say package errors. The translator does not read that clause, so any import without an alias outside knownStdPaths takes the meaning away from every call of errors and fmt in the package.

  • An expression that mixes a check inside the argument of errors.New or fmt.Errorf with 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. orderScope treats the constructors as calls, as it does for len. 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 two errors.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 of errors and fmt, other formats of fmt.Errorf, and a format that is not a literal.

  • An error in a struct field or a slice element.

This page is docs/decisions/2026-12-05-go-errors.md at commit 5f1d031.