From dd2d374cbe2db19a32d826299722899d8455a1d5 Mon Sep 17 00:00:00 2001 From: ltzmaxwell Date: Wed, 11 Sep 2024 16:13:49 +0800 Subject: [PATCH] fix(gnovm): correct type comparison for bool type (#2725) This closes https://github.com/gnolang/gno/issues/2719. copy from #2719: >https://github.com/gnolang/gno/pull/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.
Contributors' checklist... - [ ] 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).
--- gnovm/pkg/gnolang/preprocess.go | 3 +++ gnovm/tests/files/types/eql_0f49.gno | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gnovm/tests/files/types/eql_0f49.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index cb21160f85e..8e794d7bd55 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -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) } diff --git a/gnovm/tests/files/types/eql_0f49.gno b/gnovm/tests/files/types/eql_0f49.gno new file mode 100644 index 00000000000..b5a4bf4ed05 --- /dev/null +++ b/gnovm/tests/files/types/eql_0f49.gno @@ -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