Skip to content

Commit

Permalink
fix(gnovm): add const type is basic check
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Jul 31, 2024
1 parent 5f28803 commit 7645a59
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
d := n.(Decl)
if cd, ok := d.(*ValueDecl); ok {
checkValDefineMismatch(cd)
if cd.Const {
if !isConstTypeBasic(cd) {
panic("const type should be a basic literal")
}
}
}
// recursively predefine dependencies.
d2, ppd := predefineNow(store, last, d)
Expand Down Expand Up @@ -3383,6 +3388,7 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) {
return
}
}

for i := 0; i < len(d.NameExprs); i++ {
nx := &d.NameExprs[i]
if nx.Name == blankIdentifier {
Expand Down Expand Up @@ -3973,3 +3979,12 @@ func SaveBlockNodes(store Store, fn *FileNode) {
return n, TRANS_CONTINUE
})
}

func isConstTypeBasic(d *ValueDecl) bool {
for _, vx := range d.Values {
if _, ok := vx.(*BasicLitExpr); !ok {
return false
}
}
return true
}

0 comments on commit 7645a59

Please sign in to comment.