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: confusing error when using a keyword as package member #30039

Open
mvdan opened this issue Jan 31, 2019 · 2 comments
Open

cmd/compile: confusing error when using a keyword as package member #30039

mvdan opened this issue Jan 31, 2019 · 2 comments
Labels
Milestone

Comments

@mvdan
Copy link
Member

@mvdan mvdan commented Jan 31, 2019

$ go version
go version devel +447965d4e0 Sun Jan 27 04:18:10 2019 +0000 linux/amd64
$ cat f.go
package p

import "go/types"

func _() {
        var _ types.const
}
$ go build f.go
# command-line-arguments
./f.go:6:8: cannot refer to unexported name types._
./f.go:6:14: syntax error: unexpected const, expecting name

Of course, here I fat-fingered the type and meant types.Const. I encountered this in a real program, and the types._ error had me confused for a second. I presume that the first of the two errors should not be printed, as the second error contains all the information the user needs.

Interestingly enough, seems like the go/* packages don't do a particularly better job here:

f.go:6:14: expected 'IDENT', found 'const'
f.go:6:14: _ not declared by package types
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 31, 2019

Change https://golang.org/cl/160637 mentions this issue: cmd/compile: avoid confusing error on pkg.keyword

@mvdan
Copy link
Member Author

@mvdan mvdan commented Jan 31, 2019

Seemed easy enough, so I had a stab at this. I presume we should fix this in go/* as well, presumably go/parser.

@odeke-em odeke-em added this to the Go1.13 milestone Feb 3, 2019
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@andybons andybons added this to the Go1.14 milestone Jul 8, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
@smasher164 smasher164 removed this from the Backlog milestone Oct 11, 2019
@smasher164 smasher164 added this to the Go1.14 milestone Oct 11, 2019
@mvdan mvdan removed this from the Go1.14 milestone Oct 11, 2019
@mvdan mvdan added this to the Backlog milestone Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants