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

Open
findleyr opened this issue Oct 6, 2021 · 3 comments
Assignees
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr 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
@ALTree
Copy link
Member

@ALTree 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

@griesemer griesemer commented Oct 6, 2021

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

@findleyr
Copy link
Contributor Author

@findleyr 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants