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): assignment operators require 1 expression on both sides #1943

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,13 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
}
} else { // ASSIGN.
// NOTE: Keep in sync with DEFINE above.
if len(n.Lhs) > len(n.Rhs) {
if n.Op == SHL_ASSIGN || n.Op == SHR_ASSIGN {
if len(n.Lhs) != 1 || len(n.Rhs) != 1 {
panic("should not happen")
thehowl marked this conversation as resolved.
Show resolved Hide resolved
}
// Special case if shift assign <<= or >>=.
checkOrConvertType(store, last, &n.Rhs[0], UintType, false)
} else if len(n.Lhs) > len(n.Rhs) {
// TODO dry code w/ above.
// Unpack n.Rhs[0] to n.Lhs[:]
if len(n.Rhs) != 1 {
Expand Down Expand Up @@ -1641,12 +1647,6 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
default:
panic("should not happen")
}
} else if n.Op == SHL_ASSIGN || n.Op == SHR_ASSIGN {
if len(n.Lhs) != 1 || len(n.Rhs) != 1 {
panic("should not happen")
}
// Special case if shift assign <<= or >>=.
checkOrConvertType(store, last, &n.Rhs[0], UintType, false)
} else {
// General case: a, b = x, y.
for i, lx := range n.Lhs {
Expand Down
12 changes: 12 additions & 0 deletions gnovm/tests/files/assign22.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

func main() {
m := map[string]int{"a": 1}
var s int
var ok bool
s, ok <<= m["a"]
println(s, ok)
}

// Error:
// main/files/assign22.gno:7: should not happen
Loading