Skip to content

Commit

Permalink
fix(gnovm): forbid star expression when value is not a pointer (#2984)
Browse files Browse the repository at this point in the history
closes: #1088 
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>
  • Loading branch information
omarsy authored Oct 30, 2024
1 parent 9786fa3 commit 850182c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,12 @@ func preprocess1(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)
Expand Down
9 changes: 9 additions & 0 deletions gnovm/tests/files/ptr9.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

func main() {
v := 1
println(*v)
}

// Error:
// main/files/ptr9.gno:5:10: invalid operation: cannot indirect v<VPBlock(1,0)> (variable of type int)

0 comments on commit 850182c

Please sign in to comment.