-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): assignment operators require 1 expression on both sides (#…
…1943) > This PR fixes a bug in the GnoVM which executes incorrect statements like `s, ok <<= m["a"]`. The following code currently executes on gno: ```go package main func main() { m := map[string]int{"a": 1} var s int var ok bool s, ok <<= m["a"] println(s, ok) } ``` ![wat](https://github.com/gnolang/gno/assets/4681308/4545aadb-f255-49b0-863f-2506311f11e7) This PR matches the behaviour on assignment statements to the Go specification: > An assignment operation x op= y where op is a binary [arithmetic operator](https://go.dev/ref/spec#Arithmetic_operators) is equivalent to x = x op (y) but evaluates x only once. The op= construct is a single token. **In assignment operations, both the left- and right-hand expression lists must contain exactly one single-valued expression,** and the left-hand expression must not be the blank identifier.
- Loading branch information
Showing
3 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: assignment operator <<= requires only one expression on lhs and rhs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/assign23.gno:7: assignment operator += requires only one expression on lhs and rhs |