Skip to content

Commit 850182c

Browse files
authored
fix(gnovm): forbid star expression when value is not a pointer (#2984)
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>
1 parent 9786fa3 commit 850182c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: gnovm/pkg/gnolang/preprocess.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,12 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
17571757
case *KeyValueExpr:
17581758
// NOTE: For simplicity we just
17591759
// use the *CompositeLitExpr.
1760-
1760+
// TRANS_LEAVE -----------------------
1761+
case *StarExpr:
1762+
xt := evalStaticTypeOf(store, last, n.X)
1763+
if xt.Kind() != PointerKind && xt.Kind() != TypeKind {
1764+
panic(fmt.Sprintf("invalid operation: cannot indirect %s (variable of type %s)", n.X.String(), xt.String()))
1765+
}
17611766
// TRANS_LEAVE -----------------------
17621767
case *SelectorExpr:
17631768
xt := evalStaticTypeOf(store, last, n.X)

Diff for: gnovm/tests/files/ptr9.gno

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
func main() {
4+
v := 1
5+
println(*v)
6+
}
7+
8+
// Error:
9+
// main/files/ptr9.gno:5:10: invalid operation: cannot indirect v<VPBlock(1,0)> (variable of type int)

0 commit comments

Comments
 (0)