Skip to content

Go methods with a value receiver ​

Status: accepted · Date: 2026-11-30

The proved path refused every declaration with a receiver. This record adds methods with a value receiver on a struct type, and calls of them.

The decision ​

  • Eval.asFunc (tolean/Go/Spec/Eval.lean) reads a method func (r T) M(ps) R { … } as the function T.M(r T, ps) R. The name T.M cannot be a Go identifier, so it never clashes with a function or a local. The interpreter's functions and the translator's findFunc both come from these declarations, so the proof of a function covers a method unchanged.
  • x.M(a, …) calls T.M(x, a, …): the receiver is evaluated first, then the arguments in order, and the receiver is a copy (Go specification, "Calls", "Method declarations", "Order of evaluation"). The interpreter finds T.M through Program.methods, which holds a method name only when one method of the package declares it. Then a call x.M(…) that Go accepts can only call that method: the subset has no embedded fields, interfaces or fields of function type.
  • The translator checks that x has the struct type T and that the table gives T.M, and writes T.M x a …. In the output, T.M is a function in the namespace of the structure T. eval_method and the method case of the expression proof reuse the proof for function calls.
  • The corpus package methods, tests/go/Methods.lean and the differential generator cover the form.

Refused ​

A receiver without a name was refused here at first, as parameters without a name were. Both are accepted now: the interpreter binds the name _, and so does the output.

  • Pointer receivers: the subset has no pointers or aliasing yet.
  • Methods on types other than structs, such as type C int. The translator gives such a value its underlying type, so it cannot tell which method a call names.
  • A method name that several types declare. Choosing between them needs the static type in the interpreter, which its values do not carry.
  • Calls of methods that can panic. A call of a function that can panic must stand alone after :=, =, var or return, and that bind form does not take a method call yet.
  • Method values and method expressions (x.M without a call, T.M), embedding and interfaces that the package implements.

This page is docs/decisions/2026-11-30-go-methods.md at commit 5f1d031.