mirror of
https://github.com/golang/go
synced 2024-11-13 12:40:26 -07:00
Apply review suggestions.
This commit is contained in:
parent
4e1e987d9f
commit
cd042fdc38
@ -335,17 +335,13 @@ func (check *Checker) cycleError(cycle []Object, start int) {
|
||||
} else {
|
||||
err.addf(obj, "invalid cycle in declaration of %s", objName)
|
||||
}
|
||||
i := start
|
||||
for range cycle {
|
||||
currName := objName
|
||||
currObj := obj
|
||||
i++
|
||||
if i >= len(cycle) {
|
||||
i = 0
|
||||
}
|
||||
obj = cycle[i]
|
||||
objName = name(obj)
|
||||
err.addf(currObj, "%s refers to %s", currName, objName)
|
||||
// "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.
|
||||
n := len(cycle)
|
||||
rotate := func(i int) int { return (i + start) % n }
|
||||
for i := range n {
|
||||
obj := cycle[rotate(i)]
|
||||
next := cycle[rotate(i+1)]
|
||||
err.addf(obj, "%s refers to %s", name(obj), name(next))
|
||||
}
|
||||
err.report()
|
||||
}
|
||||
|
@ -163,12 +163,10 @@ func (check *Checker) reportCycle(cycle []Object) {
|
||||
|
||||
err := check.newError(InvalidInitCycle)
|
||||
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
|
||||
for i := len(cycle) - 1; i >= 0; i-- {
|
||||
currObj := obj
|
||||
currName := obj.Name()
|
||||
obj = cycle[i]
|
||||
err.addf(currObj, "%s refers to %s", currName, obj.Name())
|
||||
// "cycle[i] refers to cycle[j]" for (i,j) = (0, n-1), (n-1, n-2), ..., (1,0) for len(cycle) = n.
|
||||
for j := len(cycle) - 1; j >= 0; j-- {
|
||||
err.addf(obj, "%s refers to %s", obj.Name(), cycle[j].Name())
|
||||
obj = cycle[j]
|
||||
}
|
||||
err.report()
|
||||
}
|
||||
|
@ -336,17 +336,14 @@ func (check *Checker) cycleError(cycle []Object, start int) {
|
||||
} else {
|
||||
err.addf(obj, "invalid cycle in declaration of %s", objName)
|
||||
}
|
||||
i := start
|
||||
for range cycle {
|
||||
currName := objName
|
||||
currObj := obj
|
||||
i++
|
||||
if i >= len(cycle) {
|
||||
i = 0
|
||||
}
|
||||
obj = cycle[i]
|
||||
objName = name(obj)
|
||||
err.addf(currObj, "%s refers to %s", currName, objName)
|
||||
|
||||
// "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.
|
||||
n := len(cycle)
|
||||
rotate := func(i int) int { return (i + start) % n }
|
||||
for i := range n {
|
||||
obj := cycle[rotate(i)]
|
||||
next := cycle[rotate(i+1)]
|
||||
err.addf(obj, "%s refers to %s", name(obj), name(next))
|
||||
}
|
||||
err.report()
|
||||
}
|
||||
|
@ -166,12 +166,10 @@ func (check *Checker) reportCycle(cycle []Object) {
|
||||
|
||||
err := check.newError(InvalidInitCycle)
|
||||
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
|
||||
for i := len(cycle) - 1; i >= 0; i-- {
|
||||
currObj := obj
|
||||
currName := obj.Name()
|
||||
obj = cycle[i]
|
||||
err.addf(currObj, "%s refers to %s", currName, obj.Name())
|
||||
// "cycle[i] refers to cycle[j]" for (i,j) = (0, n-1), (n-1, n-2), ..., (1,0) for len(cycle) = n.
|
||||
for j := len(cycle) - 1; j >= 0; j-- {
|
||||
err.addf(obj, "%s refers to %s", obj.Name(), cycle[j].Name())
|
||||
obj = cycle[j]
|
||||
}
|
||||
err.report()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user