Skip to content

Commit

Permalink
fix(gnovm): check type
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed Dec 26, 2024
1 parent 59a7d85 commit 9dab0d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gnovm/pkg/gnolang/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ func assertValidConstExpr(store Store, last BlockNode, n *ValueDecl, expr Expr)
}
}

nt := evalStaticTypeOf(store, last, expr)
if xnt, ok := nt.(*NativeType); ok {
nt = go2GnoBaseType(xnt.Type)
}

if nt == nil {
panic(fmt.Sprintf("%s (variable of type nil) is not constant", expr))
}

if _, ok := baseOf(nt).(PrimitiveType); !ok {
panic(fmt.Sprintf("%s (variable of type %s) is not constant", expr, nt))
}

assertValidConstValue(store, last, expr, nil)
}

Expand Down
10 changes: 10 additions & 0 deletions gnovm/tests/files/const44.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

const a = interface{}(nil)

func main() {
println("ok")
}

// Error:
// main/files/const44.gno:3:7: (const (undefined)) (variable of type interface{}) is not constant

0 comments on commit 9dab0d3

Please sign in to comment.