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: failing type inference produces unclear error message #60542

Open
griesemer opened this issue May 31, 2023 · 2 comments
Open

cmd/compile: failing type inference produces unclear error message #60542

griesemer opened this issue May 31, 2023 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. TypeInference Issue is related to generic type inference
Milestone

Comments

@griesemer
Copy link
Contributor

Taken from #60434:

package p

func Clip[S ~[]E, E any](s S) S {
	return s
}

var versions func()
var _ = Clip(versions)

produces:

/tmp/x.go:8:13: S does not match []E

which is not helpful.

Suggestion by @rsc :

It would be helpful to say what function is being called and what S is, as in:

/tmp/x.go:8:13: in call to slices.Clip, S (type func()) does not match []E
@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label May 31, 2023
@griesemer griesemer added this to the Go1.21 milestone May 31, 2023
@griesemer griesemer self-assigned this May 31, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 31, 2023
@gopherbot
Copy link

Change https://go.dev/cl/499639 mentions this issue: go/typs, types2: better error message for some inference failures

@griesemer
Copy link
Contributor Author

@rsc The CL above gets us halfway there. We can do a whole lot better but probably not for Go 1.21.

gopherbot pushed a commit that referenced this issue May 31, 2023
For a unification failure involving a constraint, rather than just
reporting (for instance)

        S does not match []E

now report the inferred type for the type parameter, use spec
terminology when referring to the constraint, and print the
constraint in full:

        S (type func()) does not satisfy ~[]E

There's more we can do, but this is better than what we had.

For #60542.

Change-Id: I033369fa0dfc475f0ec0da0582e8cbefb109f3cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/499639
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@griesemer griesemer modified the milestones: Go1.21, Go1.22 Jun 1, 2023
Nasfame pushed a commit to golangFame/go that referenced this issue Jun 4, 2023
For a unification failure involving a constraint, rather than just
reporting (for instance)

        S does not match []E

now report the inferred type for the type parameter, use spec
terminology when referring to the constraint, and print the
constraint in full:

        S (type func()) does not satisfy ~[]E

There's more we can do, but this is better than what we had.

For golang#60542.

Change-Id: I033369fa0dfc475f0ec0da0582e8cbefb109f3cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/499639
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@griesemer griesemer added the TypeInference Issue is related to generic type inference label Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. TypeInference Issue is related to generic type inference
Projects
Status: In Progress
Development

No branches or pull requests

2 participants