Skip to content

Commit

Permalink
fix(gnovm): in op_binary, return typed booleans where appropriate (gn…
Browse files Browse the repository at this point in the history
…olang#3298)

bool8.gno was failing, because the result of the `==` expression is an
untyped boolean, while the first value is a typed boolean. This PR
ensures that if either of the values in a binary expression is typed, we
return a typed bool instead of an untyped bool.

---------

Co-authored-by: ltzmaxwell <[email protected]>
  • Loading branch information
thehowl and ltzmaxwell authored Dec 11, 2024
1 parent c33cf67 commit 7185cef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3574,6 +3574,10 @@ func checkOrConvertType(store Store, last BlockNode, n Node, x *Expr, t Type, au
checkOrConvertType(store, last, n, &bx.Left, rt, autoNative)
checkOrConvertType(store, last, n, &bx.Right, rt, autoNative)
}
// this is not a constant expression; the result here should
// always be a BoolType. (in this scenario, we may have some
// UntypedBoolTypes)
t = BoolType
default:
// do nothing
}
Expand Down
17 changes: 17 additions & 0 deletions gnovm/tests/files/bool8.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

// results from comparisons should not be untyped bools

var a interface{} = true

func main() {
buf := "hello="
isEqual(a, (buf[len(buf)-1] == '='))
}

func isEqual(v1, v2 interface{}) {
println("v1 == v2", v1 == v2)
}

// Output:
// v1 == v2 true

0 comments on commit 7185cef

Please sign in to comment.