Skip to content

cmd/compile: misleading error message when struct lacks expected type parameters #49541

@rogpeppe

Description

@rogpeppe

commit 1ec5108

I compiled the following (incorrect) code: https://gotipplay.golang.org/p/NF9UzMFrJG1

type S[A, B any] struct {
	F int
}

func f[A any](s S[A]) {
	s.F = 1
}

I see these error messages:

./prog.go:10:17: cannot infer B (prog.go:6:11)
./prog.go:10:17: got 1 arguments but 2 type parameters
./prog.go:11:4: s.F undefined (type S[A] has no field or method F)

The last error message is misleading because S actually does have a field named F even if it hasn't been instantiated with the required type parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions