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

boolean operators (||, &&) allowed in return values (for non-boolean return values) #1083

Closed
thehowl opened this issue Aug 30, 2023 · 0 comments · Fixed by #1451
Closed

boolean operators (||, &&) allowed in return values (for non-boolean return values) #1083

thehowl opened this issue Aug 30, 2023 · 0 comments · Fixed by #1451
Assignees
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@thehowl
Copy link
Member

thehowl commented Aug 30, 2023

example:

package main

func main() {
	println(X())
	println(Y())
	println(Z())
}

func X() string {
	return "alfa" || "beta"
}

func Y() byte {
	return 0 || 9
}

func Z() [1]bool {
	return [1]bool{true} && [1]bool{false}
}

this program executes with gno run with the following output:

alfa
0
array[(true bool)]

It seems to me that only the first expression is evaluated & returned.

I first discovered this as I made a typo in this function. I intended to do a bitwise OR, then I noticed some weird behaviour elsewhere and noticed that the return expression contained this || while it was not allowed.

(Part of a series of issues encountered while developing gnochess)

@thehowl thehowl added 🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related labels Aug 30, 2023
@thehowl thehowl changed the title boolean operators (||, &&) allowed in return values boolean operators (||, &&) allowed in return values (for non-boolean return values) Aug 30, 2023
@moul moul added this to the 🚀 main.gno.land milestone Sep 6, 2023
@deelawn deelawn self-assigned this Dec 17, 2023
@deelawn deelawn linked a pull request Dec 17, 2023 that will close this issue
7 tasks
jaekwon pushed a commit that referenced this issue Dec 18, 2023
<!-- please provide a detailed description of the changes made in this
pull request. -->
Addresses #1083

This fixes an issue where there was no enforcement of operand types when
doing boolean operations. The correct approach should be to verify
boolean operand type expressions also evaluate to boolean typed values
before proceeding. This prevents any of the behavior described in the
issue that this PR addresses.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
gfanton pushed a commit to moul/gno that referenced this issue Jan 18, 2024
<!-- please provide a detailed description of the changes made in this
pull request. -->
Addresses gnolang#1083

This fixes an issue where there was no enforcement of operand types when
doing boolean operations. The correct approach should be to verify
boolean operand type expressions also evaluate to boolean typed values
before proceeding. This prevents any of the behavior described in the
issue that this PR addresses.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: 🚀 Needed for Launch
Development

Successfully merging a pull request may close this issue.

3 participants