Skip to content

Commit 8c49d8f

Browse files
committed
types2: ensure that the reportCycle has a deterministic output
Fixes #71254
1 parent 6da1601 commit 8c49d8f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/cmd/compile/internal/types2/initorder.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,15 @@ func findPath(objMap map[Object]*declInfo, from, to Object, seen map[Object]bool
139139
}
140140
seen[from] = true
141141

142-
for d := range objMap[from].deps {
143-
if d == to {
144-
return []Object{d}
145-
}
142+
if _, found := objMap[from].deps[to]; found {
143+
return []Object{to}
144+
}
145+
146+
// Sort in order to return a deterministic path, thereby guaranteeing consistent output in the `reportCycle`.
147+
deps := slices.SortedFunc(maps.Keys(objMap[from].deps), func(o1 Object, o2 Object) int {
148+
return int(o1.order()) - int(o2.order())
149+
})
150+
for _, d := range deps {
146151
if P := findPath(objMap, d, to, seen); P != nil {
147152
return append(P, d)
148153
}

0 commit comments

Comments
 (0)