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/go: internal package is importable to the packages which is not rooted in the same subtree. #12217

Closed
bigwhite opened this issue Aug 20, 2015 · 4 comments

Comments

@bigwhite
Copy link

$go version
go version go1.5 darwin/amd64
$uname -a
Darwin TonydeMacBook-Air-2.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64

the project layout is below: (GOPATH=/home/bigwhite/gotestinternal)

/home/bigwhite/gotestinternal
└── src
    ├── mypkg
    │   ├── internal
    │   │   └── foo
    │   │       └── foo.go
    │   ├── main.o
    │   └── pkg1
    │       ├── main
    │       └── main.go
    └── otherpkg
        └── main.go

I am trying to test the internal package in go 1.5 final release. according to the internal design doc, if we import internal/foo in mypkg/main.go or mypkg/pkg1/main.go, it is ok. but if we import mypkg/internal/foo in otherpkg/main.go, it should be invalid.

But the test result is not as the above:

//otherpkg/main.go
package main

import "mypkg/internal/foo"

func main() {
    foo.Foo()
}

we build otherpkg/main.go in otherpkg directory, but no error occurs. It is not the result expected.
but go list -json tell us we has a not-allowed use of internal package:

"DepsErrors": [
        {
            "ImportStack": [
                "otherpkg",
                "mypkg/internal/foo"
            ],
            "Pos": "",
            "Err": "use of internal package not allowed"
        }
    ]

I'm not sure whether it is a problem of go1.5.

@bigwhite bigwhite changed the title go 1.5 internal package is importableby packages rooted in the same subtree. go 1.5: internal package is importable to the packages which is not rooted in the same subtree. Aug 20, 2015
@bigwhite bigwhite reopened this Aug 20, 2015
@ianlancetaylor ianlancetaylor changed the title go 1.5: internal package is importable to the packages which is not rooted in the same subtree. cmd/go: internal package is importable to the packages which is not rooted in the same subtree. Aug 20, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 20, 2015
@rsc
Copy link
Contributor

rsc commented Dec 17, 2015

I can believe there is a bug here. The last one was #11331 fixed by https://go-review.googlesource.com/#/c/12450/, but that was before Go 1.5 and the report says the problem happened with Go 1.5.

However, I cannot reproduce this. In addition to what's in the initial report, I need:

  • the exact contents of all the relevant source files
  • the exact command being run

I have tried to guess these, in particular by running various exhaustive searches over possible ways the imports could be arranged, and I cannot find any cases where otherpkg would be allowed to import mypkg/internal/foo.

If you still have the information available, can you give us more detail? Thanks.

@rsc rsc modified the milestones: Go1.6Maybe, Go1.6 Dec 17, 2015
@bigwhite
Copy link
Author

hi @rsc ,

For the sake of a conveniency debuging, I pushed the code into my experiments repository on github.

github.com/bigwhite/experiments/go15-internal-issue-12217]$tree
.
├── mypkg
│   ├── internal
│   │   └── foo
│   │       └── foo.go
│   ├── main.go
│   └── pkg1
│       └── main.go
└── otherpkg
    └── main.go

5 directories, 4 files

I ran the example again on both Mac and ubuntu,the problem can still be reproduceable. the steps are like below:

on Darwin(Darwin TonydeMacBook-Air-2.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64), go 1.5.1

$go get github.com/bigwhite/experiments/go15-internal-issue-12217
$cd $GOPATH/src/github.com/bigwhite/experiments/go15-internal-issue-12217
$cd mypkg
$go run main.go
Foo in github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo  // it is ok
$cd pkg1
$ go run main.go
Foo in github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo //it is ok
$ cd $GOPATH/src/github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg
$go run main.go
Foo in github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo //it is unexpected result
$go list -json

{
    "Dir": "/Users/tony/Test/GoToolsProjects/src/github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg",
    "ImportPath": "github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg",
    "Name": "main",
    "Target": "/Users/tony/.bin/go151/bin/otherpkg",
    "Stale": true,
    "Root": "/Users/tony/Test/GoToolsProjects",
    "GoFiles": [
        "main.go"
    ],
    "Imports": [
        "github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo"
    ],
    "Deps": [
        "errors",
        "fmt",
        "github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo",
        "io",
        "math",
        "os",
        "reflect",
        "runtime",
        "strconv",
        "sync",
        "sync/atomic",
        "syscall",
        "time",
        "unicode/utf8",
        "unsafe"
    ],
    "Incomplete": true,
    "DepsErrors": [
        {
            "ImportStack": [
                "github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg",
                "github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo"
            ],
            "Pos": "",
            "Err": "use of internal package not allowed"
        }
    ]
}

On linux ( 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux) go 1.5.2,I got the same result after executing the same steps above.

@bigwhite
Copy link
Author

But I found go build command is correct to detect the internal not allowed error.

$ go build github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg/
package github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg
    imports github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo: use of internal package not allowed

go run can not detect the error:

$go run /Users/tony/Test/GoToolsProjects/src/github.com/bigwhite/experiments/go15-internal-issue-12217/otherpkg/main.go
Foo in github.com/bigwhite/experiments/go15-internal-issue-12217/mypkg/internal/foo

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Jan 13, 2017
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