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): improve error message for nil assignment in variable decl… #3068

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func checkAssignableTo(xt, dt Type, autoNative bool) error {
// case0
if xt == nil { // see test/files/types/eql_0f18
if !maybeNil(dt) {
panic(fmt.Sprintf("invalid operation, nil can not be compared to %v", dt))
panic(fmt.Sprintf("cannot use nil as %v value in variable declaration", dt))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for tackling this.

}
return nil
} else if dt == nil { // _ = xxx, assign8.gno, 0f31. else cases?
Expand Down
10 changes: 10 additions & 0 deletions gnovm/tests/files/assign29.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func main() {
a := 1
a = nil
println(a)
}

// Error:
// main/files/assign29.gno:5:2: cannot use nil as int value in variable declaration
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be cannot use nil as int value in assignment

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

func main() {
var i int = nil
}

// Error:
// main/files/var31.gno:4:6: cannot use nil as int value in variable declaration
Loading