criswxart / go-tour

Automatically exported from code.google.com/p/go-tour
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Slices Exercise Produces an Error #182

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.If the exact slice.go solution is ran it generates an error.
prog.go:13: invalid operation: row[x] (type uint8 does not support indexing)
 [process exited with non-zero status]

What is the expected output? What do you see instead?
This Should compile without an error.

What version of the product are you using? On what operating system?
Latest Version

Please provide any additional information below.
The solution to this issue is to move the row assignment in the second for loop.

Current:
        for y := range p {
                for x, row := range p[y] {
                        row[x] = uint8(x * y)
                }
        }
Correct
        for y, row := range p {
                for x := range p[y] {
                        row[x] = uint8(x * y)
                }
        }

Original issue reported on code.google.com by artemche...@gmail.com on 2 Oct 2014 at 6:03

GoogleCodeExporter commented 8 years ago
The code that I see in slices.go is the correct code:

    for y, row := range p {
        for x := range row {
            row[x] = uint8(x * y)
        }
    }

Original comment by a...@golang.org on 4 Oct 2014 at 7:13