Skip to content

cmd/compile: missing "imported and not used" error for dot-import #6428

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

Closed
griesemer opened this issue Sep 19, 2013 · 9 comments
Closed

cmd/compile: missing "imported and not used" error for dot-import #6428

griesemer opened this issue Sep 19, 2013 · 9 comments

Comments

@griesemer
Copy link
Contributor

cat x.go
package main

import . "testing"  // declares T in file scope

type S struct {
     T int
}

func main() {
     _ = S{T: 0}
}

go tool 6g x.go produces no error. However, it should complain with:

x.go:3: imported and not used: "testing"

Note that changing the assignment in main to:

     _ = S{}

produces the expected error (actually, a slightly confused error message, see issue also
6420).
The "T" in S{T: 0} is not the same T as the one imported.
@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 1:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 2:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added repo-main.

@gopherbot
Copy link
Contributor

Comment 4:

CL https://golang.org/cl/162390044 mentions this issue.

@rsc rsc removed the compiler-bug label Apr 10, 2015
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: missing "imported and not used" error for dot-import cmd/compile: missing "imported and not used" error for dot-import Jun 8, 2015
@griesemer griesemer assigned griesemer and unassigned rsc Dec 24, 2017
@griesemer griesemer modified the milestones: Unplanned, Go1.11 Dec 24, 2017
@griesemer
Copy link
Contributor Author

Moving to 1.11 to make it visible.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/106122 mentions this issue: cmd/compile: don't use packages of keys of composite literals prematurely

@griesemer
Copy link
Contributor Author

griesemer commented Jun 5, 2018

Not urgent.

@griesemer griesemer modified the milestones: Go1.11, Unplanned Jun 5, 2018
@odeke-em odeke-em self-assigned this Jun 6, 2020
@gopherbot
Copy link
Contributor

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>
@mdempsky
Copy link
Contributor

Fixed on dev.regabi.

@golang golang locked and limited conversation to collaborators Jan 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants