Skip to content

cmd/compile: expression calling an undefined method gets adorned with receiver's type in error message #76103

@jfrech

Description

@jfrech

Compiling the following on the Go playground (go version 1.25; cf. https://go.dev/play/p/fTm-OR3aJ3a [2025-10-29])

package main

type S struct{}

func (S) G() {}

func main() {
	var s S
	_ = must(s.F())
}

func must[T any](x T, err error) T {
	if err != nil {
		panic(err)
	}
	return x
}

gives the rather thought-provoking two error messages:

./prog.go:10:11: not enough arguments in call to must
	have (S)
	want (T, error)
./prog.go:10:13: s.F undefined (type S has no field or method F)

Regarding the first one, I would have expected something along the lines of:

	have (undefined)

Metadata

Metadata

Assignees

Labels

BadErrorMessageIssues related compiler error messages that should be better.BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions