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 a67d677
Show file tree
Hide file tree
Showing 3 changed files with 19 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
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
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 a67d677

Please sign in to comment.