golang/go

cmd/link: improve error for missing method body

Open

#48,780 opened on Oct 4, 2021

View on GitHub
 (20 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsInvestigationcompiler/runtimehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

The language permits omitting the method body. However, the error message for this could be clearer.

Test case (uses import "C" to force the compiler to assume that method bodies are defined elsewhere):

package main

import "C"

type S struct{}

func (S) M()

var Sink interface{}

func main() {
	Sink = S{}
}

Running go build foo.go produces

type.main.S: relocation target main.S.M not defined

This error message is accurate but conveys little information to someone unfamiliar with linker jargon like "relocation target." We should instead say "missing function body", though unfortunately it may be difficult to give a good file/line position for the declaration with the missing body.

Contributor guide