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

This comment has been minimized.

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

This comment has been minimized.

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
@bcmills bcmills added the NeedsFix label Mar 1, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@smasher164 smasher164 modified the milestones: Backlog, Go1.14 Oct 11, 2019
@mvdan mvdan modified the milestones: Go1.14, Backlog Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.