aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2021-03-12 09:51:50 -0800
committerCarlos Amedee <carlos@golang.org>2021-08-02 22:23:30 +0000
commit0fb1e1438b02072bb9c3c566b40ad66b1ffed365 (patch)
tree96c84abb12d89d521b28849f5754b2cd703f68ef
parentaccf363d5da864521c90b152fb734f3f15e00521 (diff)
downloadgo-0fb1e1438b02072bb9c3c566b40ad66b1ffed365.tar.gz
go-0fb1e1438b02072bb9c3c566b40ad66b1ffed365.zip
[release-branch.go1.16] cmd/go/internal/load: always set IsImportCycle when in a cycle
When hitting an import cycle in reusePackage, and there is already an error set, make sure IsImportCycle is set so that we don't end up stuck in a loop. Updates #25830 Fixes #47348 Change-Id: Iba966aea4a637dfc34ee22782a477209ac48c9bd Reviewed-on: https://go-review.googlesource.com/c/go/+/301289 Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> (cherry picked from commit cdd08e615a9b92742b21a94443720b6d70452510) Reviewed-on: https://go-review.googlesource.com/c/go/+/336649 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com>
-rw-r--r--src/cmd/go/internal/load/pkg.go5
-rw-r--r--src/cmd/go/testdata/script/list_err_cycle.txt15
2 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 8b12faf4cd..61fde895f8 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -1323,6 +1323,11 @@ func reusePackage(p *Package, stk *ImportStack) *Package {
Err: errors.New("import cycle not allowed"),
IsImportCycle: true,
}
+ } else if !p.Error.IsImportCycle {
+ // If the error is already set, but it does not indicate that
+ // we are in an import cycle, set IsImportCycle so that we don't
+ // end up stuck in a loop down the road.
+ p.Error.IsImportCycle = true
}
p.Incomplete = true
}
diff --git a/src/cmd/go/testdata/script/list_err_cycle.txt b/src/cmd/go/testdata/script/list_err_cycle.txt
new file mode 100644
index 0000000000..44b82a62b0
--- /dev/null
+++ b/src/cmd/go/testdata/script/list_err_cycle.txt
@@ -0,0 +1,15 @@
+# Check that we don't get infinite recursion when loading a package with
+# an import cycle and another error. Verifies #25830.
+! go list
+stderr 'found packages a \(a.go\) and b \(b.go\)'
+
+-- go.mod --
+module errcycle
+
+go 1.16
+-- a.go --
+package a
+
+import _ "errcycle"
+-- b.go --
+package b \ No newline at end of file