Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
}
xt = xt.Elem()
n.IsArrayPtr = true
case ArrayKind, SliceKind:
default:
panic(fmt.Sprintf(
"range iteration requires map, string, array, slice, or pointer to array; got %s",
xt.Kind().String(),
))
}
// key value if define.
if n.Op == DEFINE {
Expand Down
13 changes: 13 additions & 0 deletions gnovm/tests/files/range10.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

func main() {
i := [3]int{1, 2, 3}
for j := range &i {
println(j)
}
}

// Output:
// 0
// 1
// 2
14 changes: 14 additions & 0 deletions gnovm/tests/files/range11.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

func main() {
i := []int{1, 2, 3}
for j := range &i {
println(j)
}
}

// Error:
// main/range11.gno:5:2-7:3: range iteration over pointer requires array elem type

// TypeCheckError:
// main/range11.gno:5:17: cannot range over &i (value of type *[]int)
14 changes: 14 additions & 0 deletions gnovm/tests/files/range12.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

func main() {
// Iterator syntax in latest go versions. Currently unsupported in Gno.
p := func(yield func(v int) bool) {
yield(123)
}
for j := range p {
println(j)
}
}

// Error:
// main/range12.gno:8:2-10:3: range iteration requires map, string, array, slice, or pointer to array; got FuncKind
9 changes: 9 additions & 0 deletions gnovm/tests/files/range9.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

func main() {
for range 1000 {
}
}

// Error:
// main/range9.gno:4:2-5:3: range iteration requires map, string, array, slice, or pointer to array; got BigintKind
Loading