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

Closed
griesemer opened this issue May 31, 2023 · 3 comments
Closed

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

griesemer opened this issue May 31, 2023 · 3 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
Contributor

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
@griesemer griesemer added the TypeInference Issue is related to generic type inference label Aug 16, 2023
@griesemer griesemer modified the milestones: Go1.22, Go1.23 Nov 15, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/558035 mentions this issue: go/types, types2: better error msg when type inference fails in a call

ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
In Checker.infer, report an error through an (incoming) *error_
so that the error can be reported as desired where infer is called.
Checker.infer is now a pure function.

Fixes golang#60543.

At call sites of Checker.infer, pass in an *error_ and use it to
report inference errors, together with additional information as
desired.

Fixes golang#60542.

In go/types, in error_.errorf, pass in a positioner rather than
a token.Pos. Also, introduce noposn, the positioner equivalent
for nopos. Adjust call sites as needed.

Change-Id: I462a7899a77a8bee2a21ba88299df237d74e0672
Reviewed-on: https://go-review.googlesource.com/c/go/+/558035
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
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
None yet
Development

No branches or pull requests

2 participants