Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): forbid star expression when value is not a pointer #2984

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Copy link
Contributor

@ltzmaxwell ltzmaxwell Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider this one:

package main

func main() {
	println(*nil)
}

but yes I'll make a new issue: #3052

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always ahead of the game :) should have let you take a look first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch. Missed this one ^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did a fix here: #3053

}
// 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)
Loading