Appearance
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 methodfunc (r T) M(ps) R { … }as the functionT.M(r T, ps) R. The nameT.Mcannot be a Go identifier, so it never clashes with a function or a local. The interpreter's functions and the translator'sfindFuncboth come from these declarations, so the proof of a function covers a method unchanged.x.M(a, …)callsT.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 findsT.MthroughProgram.methods, which holds a method name only when one method of the package declares it. Then a callx.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
xhas the struct typeTand that the table givesT.M, and writesT.M x a …. In the output,T.Mis a function in the namespace of the structureT.eval_methodand the method case of the expression proof reuse the proof for function calls. - The corpus package
methods,tests/go/Methods.leanand 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
:=,=,varorreturn, and that bind form does not take a method call yet. - Method values and method expressions (
x.Mwithout 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.
