Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a67d677

Browse files
committedNov 4, 2024·
fix(gnovm): improve error message for nil assignment in variable declaration
1 parent e3995b9 commit a67d677

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎gnovm/pkg/gnolang/type_check.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func checkAssignableTo(xt, dt Type, autoNative bool) error {
289289
// case0
290290
if xt == nil { // see test/files/types/eql_0f18
291291
if !maybeNil(dt) {
292-
panic(fmt.Sprintf("invalid operation, nil can not be compared to %v", dt))
292+
panic(fmt.Sprintf("cannot use nil as %v value in variable declaration", dt))
293293
}
294294
return nil
295295
} else if dt == nil { // _ = xxx, assign8.gno, 0f31. else cases?

‎gnovm/tests/files/assign29.gno

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
func main() {
4+
a := 1
5+
a = nil
6+
println(a)
7+
}
8+
9+
// Error:
10+
// main/files/assign29.gno:5:2: cannot use nil as int value in variable declaration

‎gnovm/tests/files/var31.gno

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
func main() {
4+
var i int = nil
5+
}
6+
7+
// Error:
8+
// main/files/var31.gno:4:6: cannot use nil as int value in variable declaration

0 commit comments

Comments
 (0)
Please sign in to comment.