Skip to content

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

Closed

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

Activity

  1. added
    NeedsFixThe 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 beta1
    on Oct 27, 2021
  2. added this to the Go1.18 milestone on Oct 27, 2021
  3. self-assigned this
    on Oct 27, 2021
  4. gopherbot commented on Nov 23, 2021

    @gopherbot
    Contributor

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

  5. gopherbot commented on Nov 23, 2021

    @gopherbot
    Contributor

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

  6. gopherbot commented on Nov 26, 2021

    @gopherbot
    Contributor

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

  7. gopherbot commented on Nov 26, 2021

    @gopherbot
    Contributor

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

  8. locked and limited conversation to collaborators on Jun 23, 2023
  9. added a commit that references this issue on Sep 19, 2024
    b77f5f9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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