Skip to content

Commit

Permalink
fix(gnolang): prescriptively reject *ast.(IndexListExpr, GoStmt) as u…
Browse files Browse the repository at this point in the history
…nrecognized for Gno

The *ast.IndexListExpr is used for generics but in assignment operations
it is illegal to use. This change returns a proper error and matches
Go's output.
Also *ast.GoStmt is for spawning Go routines but those are forbidden
in Gno, hence reject them prescriptively instead of just spewing
out the raw ast type.

Fixes #3731
Updates #3751
  • Loading branch information
odeke-em committed Feb 18, 2025
1 parent fd1e9d3 commit 848e96d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gnovm/pkg/gnolang/go2gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ func Go2Gno(fs *token.FileSet, gon ast.Node) (n Node) {
}
case *ast.EmptyStmt:
return &EmptyStmt{}
case *ast.IndexListExpr:
if len(gon.Indices) > 1 {
panic(&LocationPlusError{posn(), "invalid operation: more than one index"})
}
panic(&LocationPlusError{posn(), "invalid operation: indexList is not permitted in Gno"})
case *ast.GoStmt:
panic(&LocationPlusError{posn(), "goroutines are not permitted"})
default:
panic(&LocationPlusError{posn(), fmt.Sprintf("unknown Go type %v: %s\n",
reflect.TypeOf(gon),
Expand Down
16 changes: 16 additions & 0 deletions gnovm/tests/files/goroutine_not_supported.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://github.com/gnolang/gno/issues/3751

package math

import "testing"

func Add(a, b int) int {
return a + b
}

func TestAdd(t *testing.T) {
go Add(1, 1)
}

// Error:
// goroutine_not_supported.gno:12:5: goroutines are not permitted
16 changes: 16 additions & 0 deletions gnovm/tests/files/parse_indexListExpr.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://github.com/gnolang/gno/issues/3731

package main

type node struct {
r []int
}

func (n *node) foo(targ, wndex int) {
_ = n.r[targ, wndex]
}

func main() {}

// ERROR:
// parse_indexListExpr.gno:10:6: invalid operation: more than one index

0 comments on commit 848e96d

Please sign in to comment.