From 1b70f04ebe45010c94630f41e6eb4cf295f874b1 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Thu, 13 Feb 2025 22:51:01 +0200 Subject: [PATCH] fix(gnolang): prescriptively reject *ast.(IndexListExpr, GoStmt) as unrecognized 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 --- gnovm/pkg/gnolang/go2gno.go | 7 +++++++ gnovm/tests/files/parse_err1.gno | 16 ++++++++++++++++ gnovm/tests/files/parse_err2.gno | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 gnovm/tests/files/parse_err1.gno create mode 100644 gnovm/tests/files/parse_err2.gno diff --git a/gnovm/pkg/gnolang/go2gno.go b/gnovm/pkg/gnolang/go2gno.go index b98136b13b5..8379bfef425 100644 --- a/gnovm/pkg/gnolang/go2gno.go +++ b/gnovm/pkg/gnolang/go2gno.go @@ -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") + case *ast.GoStmt: + panicWithPos("goroutines are not permitted") default: panicWithPos("unknown Go type %v: %s\n", reflect.TypeOf(gon), diff --git a/gnovm/tests/files/parse_err1.gno b/gnovm/tests/files/parse_err1.gno new file mode 100644 index 00000000000..efa21e883b0 --- /dev/null +++ b/gnovm/tests/files/parse_err1.gno @@ -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 diff --git a/gnovm/tests/files/parse_err2.gno b/gnovm/tests/files/parse_err2.gno new file mode 100644 index 00000000000..8bc923a317a --- /dev/null +++ b/gnovm/tests/files/parse_err2.gno @@ -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