Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): do not allow nil as type declaration #3309

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
thehowl marked this conversation as resolved.
Show resolved Hide resolved
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
Loading