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 24, 2025
1 parent 41a43ba commit 1b70f04
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 @@ -478,6 +478,13 @@ func Go2Gno(fs *token.FileSet, gon ast.Node) (n Node) {
}
case *ast.EmptyStmt:
return &EmptyStmt{}
case *ast.IndexListExpr:
if len(gon.Indices) > 1 {
panicWithPos("invalid operation: more than one index")
}
panicWithPos("invalid operation: indexList is not permitted in Gno")

Check warning on line 485 in gnovm/pkg/gnolang/go2gno.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/go2gno.go#L485

Added line #L485 was not covered by tests
case *ast.GoStmt:
panicWithPos("goroutines are not permitted")
default:
panicWithPos("unknown Go type %v: %s\n",
reflect.TypeOf(gon),
Expand Down
16 changes: 16 additions & 0 deletions gnovm/tests/files/parse_err1.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:
// files/parse_err1.gno:10:6: invalid operation: more than one index
16 changes: 16 additions & 0 deletions gnovm/tests/files/parse_err2.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:
// files/parse_err2.gno:12:5: goroutines are not permitted

0 comments on commit 1b70f04

Please sign in to comment.