blackcr0w/go-tour

Slices Exercise Produces an Error

Closed this issue · 1 comments

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

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

  • Changed state: Invalid