Skip to content

Commit 684912a

Browse files
omarsyn2p5
authored andcommittedJan 10, 2025
fix(gnovm): raise error when ranging over nil (#3337)
closes #3336 Co-authored-by: Nathan Toups <[email protected]>
1 parent ca77714 commit 684912a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

‎gnovm/pkg/gnolang/preprocess.go

+4
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
592592
// define key/value.
593593
n.X = Preprocess(store, last, n.X).(Expr)
594594
xt := evalStaticTypeOf(store, last, n.X)
595+
if xt == nil {
596+
panic("cannot range over nil")
597+
}
598+
595599
switch xt.Kind() {
596600
case MapKind:
597601
n.IsMap = true

‎gnovm/tests/files/range8.gno

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
func main() {
4+
for i, v := range nil {
5+
println(i, v)
6+
}
7+
}
8+
9+
// Error:
10+
// main/files/range8.gno:4:2: cannot range over nil

0 commit comments

Comments
 (0)