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

Conversation

thehowl
Copy link
Member

@thehowl thehowl commented Apr 17, 2024

This PR fixes a bug in the GnoVM which executes incorrect statements like s, ok <<= m["a"].

The following code currently executes on gno:

package main

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

wat

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 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.

@thehowl thehowl self-assigned this Apr 17, 2024
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Apr 17, 2024
@thehowl thehowl changed the title fix(gnovm): fix check for ASSIGN_SHL/SHR in preprocessor fix(gnovm): fix check for SHL/SHR_ASSIGN in preprocessor Apr 17, 2024
Copy link

codecov bot commented Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.78%. Comparing base (3d1d26c) to head (fd022c6).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1943   +/-   ##
=======================================
  Coverage   47.78%   47.78%           
=======================================
  Files         393      393           
  Lines       61608    61602    -6     
=======================================
  Hits        29437    29437           
+ Misses      29701    29695    -6     
  Partials     2470     2470           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thehowl
Copy link
Member Author

thehowl commented Apr 18, 2024

I double-checked, and this same check is supposed to be done for all assignment operators (like +=), according to the Go spec.

I've made the changes, just want to get another approval before merging this.

@thehowl thehowl changed the title fix(gnovm): fix check for SHL/SHR_ASSIGN in preprocessor fix(gnovm): assignment operators require 1 expression on both sides Apr 18, 2024
@ltzmaxwell ltzmaxwell self-requested a review April 19, 2024 03:19
@thehowl thehowl merged commit 67c437f into master Apr 19, 2024
198 of 199 checks passed
@thehowl thehowl deleted the dev/morgan/shl-shr-assign-fix branch April 19, 2024 06:14
omarsy pushed a commit to TERITORI/gno that referenced this pull request Apr 21, 2024
…nolang#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants