Home › Go

does not implement (missing method X) (Go) — how to fix

./main.go:21:17: cannot use c (variable of type Circle) as Shape value in variable declaration: Circle does not implement Shape (method Area has pointer receiver)
./main.go:25:17: cannot use s (variable of type Square) as Shape value in argument to print: Square does not implement Shape (missing method Perimeter)

Quick fix: Read the part in parentheses. missing method X: add X with exactly the interface's signature. method X has pointer receiver: pass a pointer (&c) or change the receiver to a value. wrong type for method X: make parameter and return types match exactly. Add var _ Shape = (*Circle)(nil) to catch it at the type definition.

What it means

Go interfaces are satisfied implicitly: a type implements Shape if its method set contains every method in Shape with the identical signature. When you assign, pass or return a value where Shape is expected and that isn't true, the compiler says which method is the problem and why.

type Shape interface {
    Area() float64
    Perimeter() float64
}

Cause 1: the method really is missing (or misspelled)

Square does not implement Shape (missing method Perimeter)

Add it, spelled exactly the same, including capitalization:

func (s Square) Perimeter() float64 { return 4 * s.Side }

perimeter (lowercase) is a different, unexported method. If the interface has an unexported method and lives in another package, types outside that package cannot implement it at all.

Cause 2: pointer receiver, value passed

Circle does not implement Shape (method Area has pointer receiver)
func (c *Circle) Area() float64 { return math.Pi * c.R * c.R }

var s Shape = Circle{R: 2}      // error

The method set of Circle contains only value-receiver methods; *Circle has both. Pass a pointer:

var s Shape = &Circle{R: 2}

Or, if the method doesn't modify the receiver, switch it to a value receiver:

func (c Circle) Area() float64 { return math.Pi * c.R * c.R }

Keep receivers consistent within a type: if any method needs a pointer receiver, use pointer receivers for all and pass *T everywhere.

The same rule applies to standard interfaces: http.Handle("/", myHandler{}) fails to compile when ServeHTTP has a pointer receiver. With any parameters there is no compile error, so the rule bites silently: json.Marshal(v) ignores a MarshalJSON defined on *T when you pass a non-addressable T value.

Cause 3: signature doesn't match exactly

Square does not implement Shape (wrong type for method Area)
        have Area() int
        want Area() float64

Parameter types, result types and their count must match exactly. int vs float64, error vs a concrete error type, []T vs []*T, or a missing context.Context parameter all count as different. Copy the signature from the interface definition.

Cause 4: method defined on a different type

Methods on a named type are not inherited by another named type defined from it:

type MyReader io.Reader      // interface type: fine
type Celsius float64
type Temp Celsius            // Temp gets NONE of Celsius's methods

Define the methods on the type you actually use, or embed the original type in a struct so its methods are promoted:

type Logged struct {
    *bytes.Buffer          // Logged now has Write, String, ...
}

Cause 5: interface from a different package version

If two modules use different major versions of a dependency (v1 and v2), their interfaces are different types even if they look identical. Check go.mod and make both sides import the same module path.

Catch it early

A compile-time assertion next to the type reports the problem where the type is defined, not at a distant call site:

var _ Shape = (*Circle)(nil)   // *Circle must implement Shape
var _ Shape = Square{}         // Square must implement Shape

Last updated 2026-12-03.