Skip to content

Commit

Permalink
feat: add func
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed Nov 13, 2024
1 parent 808511f commit 8e8ecd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gnovm/pkg/gnolang/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,15 @@ func checkAssignableTo(n Node, xt, dt Type, autoNative bool) error {
// case0
if xt == nil { // see test/files/types/eql_0f18
if !maybeNil(dt) {
switch n.(type) {
switch n := n.(type) {
case *ValueDecl:
panic(fmt.Sprintf("cannot use nil as %v value in variable declaration", dt))
case *AssignStmt:
panic(fmt.Sprintf("cannot use nil as %v value in assignment", dt))
case *CompositeLitExpr:
panic(fmt.Sprintf("cannot use nil as %v value in array, slice literal or map literal", dt))
case *CallExpr:
panic(fmt.Sprintf("cannot use nil as %v value in argument to %v", dt, n.Func))
default:
panic(fmt.Sprintf("cannot use nil as %v value", dt))
}
Expand Down
10 changes: 10 additions & 0 deletions gnovm/tests/files/fun28.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func f(i int) {}

func main() {
f(nil)
}

// Error:
// main/files/fun28.gno:6:2: cannot use nil as int value in argument to f<VPBlock(3,0)>

0 comments on commit 8e8ecd4

Please sign in to comment.