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

import . does not cause redeclaration errors #455

Closed
bjkail opened this issue Dec 23, 2009 · 7 comments
Closed

import . does not cause redeclaration errors #455

bjkail opened this issue Dec 23, 2009 · 7 comments

Comments

@bjkail
Copy link

bjkail commented Dec 23, 2009

What steps will reproduce the problem?
1. Compile the following programs:
a.go:
package a
var X = 0

b.go:
package main
import . "a"
var X = 0


What is the expected output? What do you see instead?
Expected:
b.go:3: X redeclared in this block
        previous declaration at a.go:2

or perhaps:
b.go:2: imported and not used: a

Actual:
(no errors)


What is your $GOOS?  $GOARCH?
GOARCH=386
GOOS=linux


Which revision are you using?  (hg identify)
7929874a70ae tip


Please provide any additional information below.
The spec for import . says "all the package's exported identifiers will be
declared in the current file's file block", so the example above should
probably be diagnosed with a redeclaration error.
@peterGo
Copy link
Contributor

peterGo commented Dec 23, 2009

Comment 1:

In file a.go you declared the variable a.X; in file b.go you declared the variable
main.X; the variables are distinct.

@bjkail
Copy link
Author

bjkail commented Dec 23, 2009

Comment 2:

That's not how I interpret the spec, but if that's the correct interpretation, the
spec also requires that the unused import be diagnosed.

@peterGo
Copy link
Contributor

peterGo commented Dec 23, 2009

Comment 3:

As you can see from this expanded version of file b.go, as expected, the most local
variable X (main.X) hides the imported variable X (a.X).
package main
import . "./a"
import a "./a"
import "fmt"
var X = 1
func main() {
    fmt.Println("X (main.X) = ", X, ", ", "a.X =", a.X)
}
which gives: X (main.X) =  1 ,  a.X = 0
The explicit period form of the package name imports all the package's exported
identifiers, whether they are used or not. Therefore, there is no error for the
unused imported identifiers.

@bjkail
Copy link
Author

bjkail commented Dec 23, 2009

Comment 4:

There should not be any "hiding".  The spec says variable X from b.go is declared in
the package scope.  The spec implies that variable X from import . "./a" should be
declared in file scope (the spec does not say this explicitly, but it does say that
imported package identifiers are declared at file scope).  Finally, the spec says "no
identifier may be declared in both the file and package block".
I understand that the reference implementation does not behave as I describe.  A
plausible resolution to this bug would be to change the spec.

@rsc
Copy link
Contributor

rsc commented Dec 23, 2009

Comment 5:

This is a real bug: the X should be a conflict,
and then if you delete the declaration of X
you should get an imported and not used error.

Owner changed to r...@golang.org.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jan 8, 2010

Comment 6:

Labels changed: added compilerbug.

@rsc
Copy link
Contributor

rsc commented Jan 19, 2010

Comment 7:

This issue was closed by revision 5a5799f.

Status changed to Fixed.

Merged into issue #-.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
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

4 participants