DiagnosticsError codes
M0014 does not implement interface
A value is used as an interface but its type lacks a method of the interface, or has it with a different signature or with a pointer receiver only.
example $ marmot build . error[M0014]: cannot use Square{…} (value of struct type Square) as Shape value in variable declaration: Square does not implement Shape (method Area has pointer receiver) --> ./main.go:7:15 | 3 | type Shape interface{ Area() float64 } | ----- `Shape` is declared here ... 5 | func (q *Square) Area() float64 { return q.s * q.s } | ------- `Area` has a pointer receiver ... 7 | var s Shape = Square{2} | ^^^^^^^^^ `Square` does not implement `Shape` | = note: `Square` lacks 1 method of `Shape`: `Area` has a pointer receiver, so only `*Square` has it help: pass a pointer (check it) | 7 - var s Shape = Square{2} 7 + var s Shape = &Square{2} | error: build failed with 1 error for more about an error, run `marmot explain M0014`
The program that produced it
package main
type Shape interface{ Area() float64 }
type Square struct{ s float64 }
func (q *Square) Area() float64 { return q.s * q.s }
var s Shape = Square{2}
func main() {}
The mistake and the fix
type Shape interface{ Area() float64 }
type Square struct{ s float64 }
func (q *Square) Area() float64 { return q.s * q.s }
var s Shape = Square{2}var s Shape = &Square{2} // *Square has AreaThe fix
Add the missing method, fix its signature, or pass a pointer when the method has a pointer receiver.
See also all error codes and marmot explain.