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: does not report full import cycle #6254

Closed
ianlancetaylor opened this issue Aug 26, 2013 · 2 comments
Closed

cmd/go: does not report full import cycle #6254

ianlancetaylor opened this issue Aug 26, 2013 · 2 comments

Comments

@ianlancetaylor
Copy link
Contributor

init.go:

package main

import "pckg_a"
import "pckg_b"

func main() {
    pckg_a.New()
    pckg_b.New()

src/pckg_a/test.go:

package pckg_a

import "pckg_b"

func New() string {
    return pckg_b.New()

src/pckg_b/test.go:

package pckg_b

import "pckg_a"

func New() string {
    return pckg_a.New()


In the directory containing init.go:

GOPATH=`pwd` go build

reports

init.go:3:8: import cycle not allowed

The bug is that it does not actually report the import cycle.

If I apply this patch to cmd/go/pkg.go:

--- a/src/cmd/go/pkg.go Sun Aug 11 13:05:51 2013 +0400
+++ b/src/cmd/go/pkg.go Mon Aug 26 09:42:19 2013 -0700
@@ -252,7 +252,7 @@
        bp.BinDir = gobin
    }
    p.load(stk, bp, err)
-   if p.Error != nil && len(importPos) > 0 {
+   if p.Error != nil && len(importPos) > 0 && p.Error.Err !=
"import cycle not allowed" {
        pos := importPos[0]
        pos.Filename = shortPath(pos.Filename)
        p.Error.Pos = pos.String()

Then the complete import cycle is reported:

package .
    imports pckg_a
    imports pckg_b
    imports pckg_a: import cycle not allowed


Recording this issue in the hopes of producing a more sensible patch.
@gopherbot
Copy link

@robpike
Copy link
Contributor

robpike commented Aug 26, 2013

Comment 2:

Status changed to Duplicate.

Merged into issue #4292.

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

3 participants