Skip to content

go/types, types2: misleading error message when type param is not comparable #48712

@findleyr

Description

@findleyr

Consider the following invalid program:

package p

func f[T any](t T) func(interface{}) bool {
	return func(x interface{}) bool {
		return x == t
	}
}

The type checker produces the error cannot compare x == t (operator == not defined for interface{}), but that's not accurate. The real problem is that T is not comparable.

CC @griesemer

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions