Skip to content

Commit

Permalink
fix(gnovm): raise error when ranging over nil (#3337)
Browse files Browse the repository at this point in the history
closes #3336

Co-authored-by: Nathan Toups <[email protected]>
  • Loading branch information
omarsy and n2p5 authored Dec 16, 2024
1 parent df92946 commit b348cc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
// define key/value.
n.X = Preprocess(store, last, n.X).(Expr)
xt := evalStaticTypeOf(store, last, n.X)
if xt == nil {
panic("cannot range over nil")
}

switch xt.Kind() {
case MapKind:
n.IsMap = true
Expand Down
10 changes: 10 additions & 0 deletions gnovm/tests/files/range8.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func main() {
for i, v := range nil {
println(i, v)
}
}

// Error:
// main/files/range8.gno:4:2: cannot range over nil

0 comments on commit b348cc2

Please sign in to comment.