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

go/importer: import errors on near struct cycle #13566

Closed
jonasi opened this issue Dec 10, 2015 · 4 comments
Closed

go/importer: import errors on near struct cycle #13566

jonasi opened this issue Dec 10, 2015 · 4 comments
Milestone

Comments

@jonasi
Copy link

jonasi commented Dec 10, 2015

see https://github.com/jonasi/golang-import-error for a repro repo

go version: happens on both go version go1.5.2 darwin/amd64 and go version devel +e05b48e Thu Dec 10 08:04:07 2015 +0000 darwin/amd64

Given the following packages:

// src/two/two.go
package two

import "encoding/json"

type A struct {
    b    *B
    json json.RawMessage
}

type B struct {
    a A
}

// src/one/one.go
package one

import "two"

type A two.A

go install one works fine, but using go/importer to import one will fail. Importing package two will work fine.

The error returned is:

reading export data: /Users/jonasi/dev/src/github.com/jonasi/golang-import-error/pkg/darwin_amd64/one.a: import error /Users/jonasi/dev/src/github.com/jonasi/golang-import-error/pkg/darwin_amd64/one.a:3:86 (byte offset = 115): encoding/json package not found
@jonasi
Copy link
Author

jonasi commented Dec 16, 2015

gentle ping, in case this was missed when the issue was created.

obviously, this manifests as a bug in commands like gotype which depend on go/importer

@minux
Copy link
Member

minux commented Dec 16, 2015 via email

@griesemer griesemer self-assigned this Dec 16, 2015
@griesemer griesemer added this to the Go1.6Maybe milestone Dec 16, 2015
@griesemer
Copy link
Contributor

Thanks for reporting this and apologies for the delay. I can reproduce this and this looks indeed like a bug:

> src gri$ mkdir one
> src gri$ cd one
> one gri$ cat - > one.go
// src/one/one.go
package one

import "two"

type A two.A
> one gri$ cd ..
> src gri$ mkdir two
> src gri$ cd two
> two gri$ cat - > two.go
// src/two/two.go
package two

import "encoding/json"

type A struct {
    b    *B
    json json.RawMessage
}

type B struct {
    a A
}
> two gri$ go build
> two gri$ go install
> two gri$ cd ../one
> one gri$ go build
> one gri$ go install
> one gri$ cd ..
> src gri$ mkdir zero
> src gri$ cd zero
> zero gri$ cat - > zero.go
package zero

import "one"
> zero gri$ gotype zero.go 
zero.go:3:8: could not import one (reading export data: /Users/gri/go/pkg/darwin_amd64/one.a: import error /Users/gri/go/pkg/darwin_amd64/one.a:3:86 (byte offset = 115): encoding/json package not found)

@griesemer griesemer modified the milestones: Go1.6, Go1.6Maybe Jan 5, 2016
@gopherbot
Copy link

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

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