Skip to content

Commit

Permalink
fix(gnovm): improve error message for nil assignment in variable decl…
Browse files Browse the repository at this point in the history
…aration
  • Loading branch information
omarsy committed Nov 4, 2024
1 parent e3995b9 commit f8443e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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))
}
return nil
} else if dt == nil { // _ = xxx, assign8.gno, 0f31. else cases?
Expand Down
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

0 comments on commit f8443e5

Please sign in to comment.