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

go/types, types2: confusing error message for invalid instantiation of non-generic type #48827

Closed
findleyr opened this issue Oct 6, 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

@findleyr
Copy link
Contributor

findleyr commented Oct 6, 2021

For the example in #48818, @ALTree pointed out that the 1.18 error message is inscrutable

package main

func main() {
	_ = &([10]bool[1]{})
}
$ gotip tool compile test.go
test.go:4:12: bool is not a generic type

I think we can and should improve the error message. An easy fix would be to pass context and position the error on the '['. For example:

test.go:4:16: invalid instantiation: bool is not a generic type

Is that sufficient?

CC @griesemer

@findleyr findleyr added this to the Go1.18 milestone Oct 6, 2021
@findleyr findleyr added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 6, 2021
@ALTree
Copy link
Member

ALTree commented Oct 6, 2021

Silly program:

package main

func main() {
	_ = int[0]
}

The 1.17 compiler says:

./test.go:4:9: invalid operation: int[0] (type int does not support indexing)

which is a great error message; tip:

./test.go:4:6: int is not a generic type

Since [0] is clearly an "indexing what it shouldn't be indexed" mistake, and not a bad generic instantiation, I wonder if it is possible to change tip so that it prints the old error message when inside the [] is an integer and not a type. Does the compiler have enough info to discriminate between the two, at the point where it reports this error?

@griesemer
Copy link
Contributor

The type-checker can definitively produce a better error message. I will take care of this.

@griesemer griesemer self-assigned this Oct 6, 2021
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 6, 2021
@findleyr
Copy link
Contributor Author

findleyr commented Oct 6, 2021

@griesemer I was thinking we could change the signature of Checker.genericType. Just saying "%s is not a generic type" is probably never sufficient.

@findleyr findleyr assigned findleyr and unassigned griesemer Oct 7, 2021
@griesemer griesemer added the okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 label Oct 21, 2021
@gopherbot
Copy link

Change https://golang.org/cl/363994 mentions this issue: go/types: return an error message from Checker.genericType

@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

4 participants