Skip to content

Commit b81d75f

Browse files
rolandshoemakercagedmantis
authored andcommitted
[release-branch.go1.15] 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 #47347 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/+/336669 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]>
1 parent ba93baa commit b81d75f

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
@@ -1280,6 +1280,11 @@ func reusePackage(p *Package, stk *ImportStack) *Package {
12801280
Err: errors.New("import cycle not allowed"),
12811281
IsImportCycle: true,
12821282
}
1283+
} else if !p.Error.IsImportCycle {
1284+
// If the error is already set, but it does not indicate that
1285+
// we are in an import cycle, set IsImportCycle so that we don't
1286+
// end up stuck in a loop down the road.
1287+
p.Error.IsImportCycle = true
12831288
}
12841289
p.Incomplete = true
12851290
}
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)