Skip to content

Commit 0fb1e14

Browse files
rolandshoemakercagedmantis
authored andcommitted
[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 <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]> (cherry picked from commit cdd08e6) Reviewed-on: https://go-review.googlesource.com/c/go/+/336649 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]>
1 parent accf363 commit 0fb1e14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/cmd/go/internal/load/pkg.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,11 @@ func reusePackage(p *Package, stk *ImportStack) *Package {
13231323
Err: errors.New("import cycle not allowed"),
13241324
IsImportCycle: true,
13251325
}
1326+
} else if !p.Error.IsImportCycle {
1327+
// If the error is already set, but it does not indicate that
1328+
// we are in an import cycle, set IsImportCycle so that we don't
1329+
// end up stuck in a loop down the road.
1330+
p.Error.IsImportCycle = true
13261331
}
13271332
p.Incomplete = true
13281333
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Check that we don't get infinite recursion when loading a package with
2+
# an import cycle and another error. Verifies #25830.
3+
! go list
4+
stderr 'found packages a \(a.go\) and b \(b.go\)'
5+
6+
-- go.mod --
7+
module errcycle
8+
9+
go 1.16
10+
-- a.go --
11+
package a
12+
13+
import _ "errcycle"
14+
-- b.go --
15+
package b

0 commit comments

Comments
 (0)