Skip to content

cmd/compile: need better error message for unsatisfied constraints due to type mismatch #49179

@griesemer

Description

@griesemer

Compiling

package p

type SliceConstraint[T any] interface {
	[]T
}

func Map[S SliceConstraint[E], E any](s S, f func(E) E) S {
	return s
}

type MySlice []int

func f(s MySlice) {
	Map[MySlice, int](s, nil)
}

produces

x.go:14:19: MySlice does not satisfy SliceConstraint[E]

It's hard to see what the error is. It should have been

type SliceConstraint[T any] interface {
	~[]T // <<< need ~ here!
}

We need to produce a better error message in cases like these. This will frustrate a lot of users.

cc: @findleyr

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.okay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions