diff --git a/gnovm/pkg/gnolang/type_check.go b/gnovm/pkg/gnolang/type_check.go index f86c44e7921..8b1d1eb1e3d 100644 --- a/gnovm/pkg/gnolang/type_check.go +++ b/gnovm/pkg/gnolang/type_check.go @@ -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? diff --git a/gnovm/tests/files/assign29.gno b/gnovm/tests/files/assign29.gno new file mode 100644 index 00000000000..1856e85e49f --- /dev/null +++ b/gnovm/tests/files/assign29.gno @@ -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 diff --git a/gnovm/tests/files/var31.gno b/gnovm/tests/files/var31.gno new file mode 100644 index 00000000000..d5571f148ca --- /dev/null +++ b/gnovm/tests/files/var31.gno @@ -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