From cc7ed1abc16056739ff92e7301930f7e90f0852a Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Sat, 19 Oct 2024 17:31:25 +0200 Subject: [PATCH] fix(gnovm): forbid start expression when value is not a pointer --- gnovm/pkg/gnolang/preprocess.go | 7 ++++++- gnovm/tests/files/ptr9.gno | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gnovm/tests/files/ptr9.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 61096626f28..598cd1b63df 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1738,7 +1738,12 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { case *KeyValueExpr: // NOTE: For simplicity we just // use the *CompositeLitExpr. - + // TRANS_LEAVE ----------------------- + case *StarExpr: + xt := evalStaticTypeOf(store, last, n.X) + if xt.Kind() != PointerKind && xt.Kind() != TypeKind { + panic(fmt.Sprintf("invalid operation: cannot indirect %s (variable of type %s)", n.X.String(), xt.String())) + } // TRANS_LEAVE ----------------------- case *SelectorExpr: xt := evalStaticTypeOf(store, last, n.X) diff --git a/gnovm/tests/files/ptr9.gno b/gnovm/tests/files/ptr9.gno new file mode 100644 index 00000000000..6e104942d81 --- /dev/null +++ b/gnovm/tests/files/ptr9.gno @@ -0,0 +1,9 @@ +package main + +func main() { + v := 1 + println(*v) +} + +// Error: +// main/files/ptr9.gno:5:10: invalid operation: cannot indirect v (variable of type int)