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: failure to diagnose re-declaring dot-imported identifiers #43167

Open
mdempsky opened this issue Dec 13, 2020 · 6 comments
Open

cmd/compile: failure to diagnose re-declaring dot-imported identifiers #43167

mdempsky opened this issue Dec 13, 2020 · 6 comments
Assignees
Labels
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Dec 13, 2020

This program should fail to compile with an error that Index was already declared due to dot-importing package bytes: https://play.golang.org/p/EAPSJQRfm2F

go/types and gccgo correctly diagnose this; cmd/compile does not.

@mdempsky mdempsky added the NeedsFix label Dec 13, 2020
@mdempsky mdempsky added this to the Go1.17 milestone Dec 13, 2020
@mdempsky mdempsky self-assigned this Dec 13, 2020
@KeKe-Li
Copy link

@KeKe-Li KeKe-Li commented Dec 14, 2020

this dot-imported identifiers diagnose , and this seem to not elegance for use dot imported.

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Dec 14, 2020

@KeKe-Li Sorry, I don't follow.

The Go spec defines how import declarations should behave: https://golang.org/ref/spec#Import_declarations. go/types and gccgo are correctly implementing that for the linked program. cmd/compile is not.

@cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Dec 14, 2020

@mdempsky seems that we don't check for re-declared when processing VarDecl in noder.go?

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Dec 14, 2020

@cuonglm I think we weren't setting Block correctly for the imported symbols, so importdot didn't set it correctly for the local aliases, and so declare didn't recognize it as a redeclaration.

I have fixes for a bunch of these dot-import issues. Just polishing up the CLs to get ready for upload.

@cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Dec 14, 2020

@cuonglm I think we weren't setting Block correctly for the imported symbols, so importdot didn't set it correctly for the local aliases, and so declare didn't recognize it as a redeclaration.

I have fixes for a bunch of these dot-import issues. Just polishing up the CLs to get ready for upload.

Ah right, seems that s.Block should be changed to types.Block in importdot.

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 14, 2020

Change https://golang.org/cl/277713 mentions this issue: [dev.regabi] cmd/compile: use ir.Ident for imported identifiers

gopherbot pushed a commit that referenced this issue Dec 15, 2020
This CL substantially reworks how imported declarations are handled,
and fixes a number of issues with dot imports. In particular:

1. It eliminates the stub ir.Name declarations that are created
upfront during import-declaration processing, allowing this to be
deferred to when the declarations are actually needed. (Eventually,
this can be deferred even further so we never have to create ir.Names
w/ ONONAME, but this CL is already invasive/subtle enough.)

2. During noding, we now use ir.Idents to represent uses of imported
declarations, including of dot-imported declarations.

3. Unused dot imports are now reported after type checking, so that we
can correctly distinguish whether composite literal keys are a simple
identifier (struct literals) or expressions (array/slice/map literals)
and whether it might be a use of a dot-imported declaration.

4. It changes the "redeclared" error messages to report the previous
position information in the same style as other compiler error
messages that reference other source lines.

Passes buildall w/ toolstash -cmp.

Fixes #6428.
Fixes #43164.
Fixes #43167.
Updates #42990.

Change-Id: I40a0a780ec40daf5700fbc3cfeeb7300e1055981
Reviewed-on: https://go-review.googlesource.com/c/go/+/277713
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
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
4 participants
You can’t perform that action at this time.