Skip to content

Commit

Permalink
fix(gnovm): correct type comparison for bool type (#2725)
Browse files Browse the repository at this point in the history
This closes #2719.

copy from #2719:
>#1890 introduced strict type
comparison, which is the correct approach but overlooked the problem
mentioned above, resulting in the comparison between bool and untyped
bool. I will provide a fix soon.
<!-- please provide a detailed description of the changes made in this
pull request. -->

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

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] 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>
  • Loading branch information
ltzmaxwell committed Sep 11, 2024
1 parent 68b8f54 commit dd2d374
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,9 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
"incompatible types in binary expression: %v %v %v",
lt.TypeID(), n.Op, rt.TypeID()))
}
// convert untyped to typed
checkOrConvertType(store, last, &n.Left, defaultTypeOf(lt), false)
checkOrConvertType(store, last, &n.Right, defaultTypeOf(rt), false)
} else { // left untyped, right typed
checkOrConvertType(store, last, &n.Left, rt, false)
}
Expand Down
21 changes: 21 additions & 0 deletions gnovm/tests/files/types/eql_0f49.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

func main() {
a := "1234"
b := "1234"

cond := a == b
println(cond)
println(cond == (a == b))
println((a == b) == cond)
println((a == b) == (a == b))
println(cond && (a == b))
println(cond || (a > b))

}

// true
// true
// true
// true
// true

0 comments on commit dd2d374

Please sign in to comment.