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/internal/types2: "cannot infer T" message confusing at end: "([<nil>])" #49272

Closed
danscales opened this issue Nov 1, 2021 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@danscales
Copy link
Contributor

On go tip (generics), just a reminder that the "cannot infer T" message is confusing at the end:

./test.go:8:11: cannot infer T (test.go:3:8) ([])

I think this is being printed out from {types2,go/types}/infer.go, so the [] is the value of targs, which is the list of inferred and not-inferred type arguments. But especially when there is only one type argument that cannot be inferred, the string '([])' is not meaningful, and may make the user think there is some bigger problem.

If some of the types can be inferred, then the inferred types are included, as in: "([string ])". So, probably just need to print out the inferred args only (with a preceding label), and print out nothing if no targs were inferred.

Here's the simple example program:

package main

func g[T interface{ int64 | int32 }](x int64) T {
	return T(x)
}

func main() {
	println(g(43))
}

@griesemer @findleyr

@griesemer griesemer self-assigned this Nov 1, 2021
@griesemer griesemer added this to the Go1.18 milestone Nov 1, 2021
@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 1, 2021
@griesemer
Copy link
Contributor

Fix forthcoming.

@gopherbot
Copy link

Change https://golang.org/cl/360554 mentions this issue: go/types, types2: remove confusing debugging output in inference error message

@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.
Projects
None yet
Development

No branches or pull requests

3 participants