Skip to content

Commit

Permalink
fix(gnovm): do not allow nil as type declaration (#3309)
Browse files Browse the repository at this point in the history
Fix #3307

---------

Co-authored-by: hieu.ha <[email protected]>
  • Loading branch information
hthieu1110 and hieu.ha authored Dec 10, 2024
1 parent bb38fb1 commit ed4ebe8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -4283,6 +4283,12 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) {
if isBlankIdentifier(tx) {
panic("cannot use _ as value or type")
}

// do not allow nil as type.
if tx.Name == "nil" {
panic("nil is not a type")
}

if tv := last.GetValueRef(store, tx.Name, true); tv != nil {
t = tv.GetType()
if dt, ok := t.(*DeclaredType); ok {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/type40.gno
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ func main() {
// 5
// 6
// 7
// yo
// yo
9 changes: 9 additions & 0 deletions gnovm/tests/files/type41.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

type A nil

func main() {
}

// Error:
// main/files/type41.gno:3:6: nil is not a type

0 comments on commit ed4ebe8

Please sign in to comment.