I was doing the exercise of "A Tour of Go", the page I was on is https://tour.golang.org/moretypes/15
And following is my code:
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
var ret [][]uint8;
var row []uint8;
for i:=uint8(0);i<uint8(dy);i++ {
row = []uint8 {}
for j:=uint8(0);j<uint8(dx);j++ {
row = append(row, i+j)
}
ret = append(ret, row)
}
return ret
}
func main() {
pic.Show(Pic)
}
When I run these codes, the console throws an error:
panic: runtime error: index out of range
goroutine 1 [running]:
panic(0x18b820, 0x1040a010)
/usr/local/go/src/runtime/panic.go:464 +0x700
golang.org/x/tour/pic.Show(0x1d7948, 0x104000e0)
/go/src/golang.org/x/tour/pic/pic.go:24 +0x540
main.main()
/tmp/sandbox969725880/main.go:19 +0x20
Does anyone have any ideas why does the error occur for this int->uint8 type conversion?Thanks!