Possible error in "go fix"

91 views
Skip to first unread message

Reinhard Wobst

unread,
Feb 16, 2026, 11:54:56 AM (4 days ago) Feb 16
to golang-nuts
To a program with

for row := 0; row < N; row++ {
        for col := 0; col < N; col++ {
                for qrow := 0; qrow < N; qrow++ {
                        for qcol := 0; qcol < N; qcol++ {

I applied "go fix" and correctly got

for row := range N {
        for col := range N {
                for qrow := range N {
                        for qcol := range N {

Very nice. But when I modified it to

for row := 1; row < N; row++ {
      for col := 2; col < N; col++ {
          for qrow := 3; qrow < N; qrow++ {
              for qcol := 4; qcol < N; qcol++ {

I got the same output what is obviously wrong.
Did I overlook something trivial?

Reinhard Wobst

unread,
Feb 16, 2026, 11:58:03 AM (4 days ago) Feb 16
to golang-nuts
P.S.: I used go 1.26.0

Stephen Illingworth

unread,
Feb 16, 2026, 12:06:04 PM (3 days ago) Feb 16
to golang-nuts
I just tried it here with go1.26.0. "go fix" treats both examples as I would expect. ie. the first example is converted and the second example is not.

first example:

for row := 0; row < N; row++ {
for col := 0; col < N; col++ {
for qrow := 0; qrow < N; qrow++ {
for qcol := 0; qcol < N; qcol++ {
}
}
}
}

is converted to:

for range N {
for range N {
for range N {
for range N {
}
}
}
}

second example:

for row := 1; row < N; row++ {
for col := 2; col < N; col++ {
for qrow := 3; qrow < N; qrow++ {
for qcol := 4; qcol < N; qcol++ {
}
}
}
}

is not converted.

Reinhard Wobst

unread,
Feb 16, 2026, 12:18:40 PM (3 days ago) Feb 16
to golang-nuts
You are right. It was a layer 8 error :-)
Reply all
Reply to author
Forward
0 new messages