1
0
mirror of https://github.com/golang/go synced 2024-11-14 13:10:21 -07:00

Apply review suggestions.

This commit is contained in:
Max Neverov 2024-10-09 01:59:04 +02:00
parent 4e1e987d9f
commit cd042fdc38
4 changed files with 23 additions and 34 deletions

View File

@ -335,17 +335,13 @@ func (check *Checker) cycleError(cycle []Object, start int) {
} else { } else {
err.addf(obj, "invalid cycle in declaration of %s", objName) err.addf(obj, "invalid cycle in declaration of %s", objName)
} }
i := start // "cycle[i] refers to cycle[j]" for (i,j) = (s, s+1), (s+1, s+2), ..., (n, 0), (0,1), ..., (s-1,s) for len(cycle) = n, s = start.
for range cycle { n := len(cycle)
currName := objName rotate := func(i int) int { return (i + start) % n }
currObj := obj for i := range n {
i++ obj := cycle[rotate(i)]
if i >= len(cycle) { next := cycle[rotate(i+1)]
i = 0 err.addf(obj, "%s refers to %s", name(obj), name(next))
}
obj = cycle[i]
objName = name(obj)
err.addf(currObj, "%s refers to %s", currName, objName)
} }
err.report() err.report()
} }

View File

@ -163,12 +163,10 @@ func (check *Checker) reportCycle(cycle []Object) {
err := check.newError(InvalidInitCycle) err := check.newError(InvalidInitCycle)
err.addf(obj, "initialization cycle for %s", obj.Name()) err.addf(obj, "initialization cycle for %s", obj.Name())
// subtle loop: print cycle[i] for i = 0, n-1, n-2, ... 1 for len(cycle) = n // "cycle[i] refers to cycle[j]" for (i,j) = (0, n-1), (n-1, n-2), ..., (1,0) for len(cycle) = n.
for i := len(cycle) - 1; i >= 0; i-- { for j := len(cycle) - 1; j >= 0; j-- {
currObj := obj err.addf(obj, "%s refers to %s", obj.Name(), cycle[j].Name())
currName := obj.Name() obj = cycle[j]
obj = cycle[i]
err.addf(currObj, "%s refers to %s", currName, obj.Name())
} }
err.report() err.report()
} }

View File

@ -336,17 +336,14 @@ func (check *Checker) cycleError(cycle []Object, start int) {
} else { } else {
err.addf(obj, "invalid cycle in declaration of %s", objName) err.addf(obj, "invalid cycle in declaration of %s", objName)
} }
i := start
for range cycle { // "cycle[i] refers to cycle[j]" for (i,j) = (s, s+1), (s+1, s+2), ..., (n, 0), (0,1), ..., (s-1,s) for len(cycle) = n, s = start.
currName := objName n := len(cycle)
currObj := obj rotate := func(i int) int { return (i + start) % n }
i++ for i := range n {
if i >= len(cycle) { obj := cycle[rotate(i)]
i = 0 next := cycle[rotate(i+1)]
} err.addf(obj, "%s refers to %s", name(obj), name(next))
obj = cycle[i]
objName = name(obj)
err.addf(currObj, "%s refers to %s", currName, objName)
} }
err.report() err.report()
} }

View File

@ -166,12 +166,10 @@ func (check *Checker) reportCycle(cycle []Object) {
err := check.newError(InvalidInitCycle) err := check.newError(InvalidInitCycle)
err.addf(obj, "initialization cycle for %s", obj.Name()) err.addf(obj, "initialization cycle for %s", obj.Name())
// subtle loop: print cycle[i] for i = 0, n-1, n-2, ... 1 for len(cycle) = n // "cycle[i] refers to cycle[j]" for (i,j) = (0, n-1), (n-1, n-2), ..., (1,0) for len(cycle) = n.
for i := len(cycle) - 1; i >= 0; i-- { for j := len(cycle) - 1; j >= 0; j-- {
currObj := obj err.addf(obj, "%s refers to %s", obj.Name(), cycle[j].Name())
currName := obj.Name() obj = cycle[j]
obj = cycle[i]
err.addf(currObj, "%s refers to %s", currName, obj.Name())
} }
err.report() err.report()
} }