Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
griesemer opened this issue Oct 27, 2021 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

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

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. release-blocker okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 labels Oct 27, 2021
@griesemer griesemer added this to the Go1.18 milestone Oct 27, 2021
@griesemer griesemer self-assigned this Oct 27, 2021
@gopherbot
Copy link

Change https://golang.org/cl/366757 mentions this issue: cmd/compile/internal/types2: better error position for instantiation failure

@gopherbot
Copy link

Change https://golang.org/cl/366758 mentions this issue: cmd/compile/internal/types2: better error message for missing ~ in constraint

gopherbot pushed a commit that referenced this issue Nov 24, 2021
…failure

- Thread type argument expressions (rather than posLists) through various
type-checker functions so we can provide a better error position.

- Adjust signatures that expect a syntax.Pos to accept a poser instead
to avoid gratuituous conversions from expressions to positions.

- Rename targsx to xlist so we use xlist consistently for expression
lists.

First step in providing a better error message for the issue below.

For #49179.

Change-Id: I8fc685a2ee4f5640f4abd35568ba32bcb34e9e84
Reviewed-on: https://go-review.googlesource.com/c/go/+/366757
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot
Copy link

Change https://golang.org/cl/367198 mentions this issue: go/types: better error position for instantiation failure

@gopherbot
Copy link

Change https://golang.org/cl/367199 mentions this issue: go/types: better error message for missing ~ in constraint

gopherbot pushed a commit that referenced this issue Nov 29, 2021
This is a port of CL 366757 from types2 to go/types,
adjusted for the different handling of index expressions
in go/types.

For #49179.

Change-Id: Ic859eb09683134d055e28c8e0cb1f3814a87dc5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/367198
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopherbot pushed a commit that referenced this issue Nov 29, 2021
This is a port of CL 366758 from types2 to go/types.

For #49179.

Change-Id: I7e1c6ffb392d5c535cf901004b7acbe8c3be9b0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/367199
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants