From f83eaa3e974ab3997d45d99582b540dc3247d20d Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 10 Dec 2024 18:47:49 +0100 Subject: [PATCH] use BoolType as result in checkOrConvertType --- gnovm/pkg/gnolang/op_binary.go | 35 +++++++++++++++++---------------- gnovm/pkg/gnolang/preprocess.go | 1 + 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gnovm/pkg/gnolang/op_binary.go b/gnovm/pkg/gnolang/op_binary.go index 3477fc61bdb..6d26fa7ce54 100644 --- a/gnovm/pkg/gnolang/op_binary.go +++ b/gnovm/pkg/gnolang/op_binary.go @@ -71,17 +71,6 @@ func (m *Machine) doOpLand() { lv.SetBool(lv.GetBool() && rv.GetBool()) } -// setMaybeUntypedBool sets lv to b; it will be untyped if both lv and rv are -// untyped; otherwise, it will be a typed bool. -func setMaybeUntypedBool(lv, rv *TypedValue, b bool) { - tp := BoolType - if isUntyped(lv.T) && isUntyped(rv.T) { - tp = UntypedBoolType - } - lv.T, lv.V = tp, nil - lv.SetBool(b) -} - func (m *Machine) doOpEql() { m.PopExpr() @@ -93,7 +82,9 @@ func (m *Machine) doOpEql() { } // set result in lv. res := isEql(m.Store, lv, rv) - setMaybeUntypedBool(lv, rv, res) + lv.T = UntypedBoolType + lv.V = nil + lv.SetBool(res) } func (m *Machine) doOpNeq() { @@ -108,7 +99,9 @@ func (m *Machine) doOpNeq() { // set result in lv. res := !isEql(m.Store, lv, rv) - setMaybeUntypedBool(lv, rv, res) + lv.T = UntypedBoolType + lv.V = nil + lv.SetBool(res) } func (m *Machine) doOpLss() { @@ -123,7 +116,9 @@ func (m *Machine) doOpLss() { // set the result in lv. res := isLss(lv, rv) - setMaybeUntypedBool(lv, rv, res) + lv.T = UntypedBoolType + lv.V = nil + lv.SetBool(res) } func (m *Machine) doOpLeq() { @@ -138,7 +133,9 @@ func (m *Machine) doOpLeq() { // set the result in lv. res := isLeq(lv, rv) - setMaybeUntypedBool(lv, rv, res) + lv.T = UntypedBoolType + lv.V = nil + lv.SetBool(res) } func (m *Machine) doOpGtr() { @@ -153,7 +150,9 @@ func (m *Machine) doOpGtr() { // set the result in lv. res := isGtr(lv, rv) - setMaybeUntypedBool(lv, rv, res) + lv.T = UntypedBoolType + lv.V = nil + lv.SetBool(res) } func (m *Machine) doOpGeq() { @@ -168,7 +167,9 @@ func (m *Machine) doOpGeq() { // set the result in lv. res := isGeq(lv, rv) - setMaybeUntypedBool(lv, rv, res) + lv.T = UntypedBoolType + lv.V = nil + lv.SetBool(res) } func (m *Machine) doOpAdd() { diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 78b11a4ebc5..8e646321396 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -3564,6 +3564,7 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative checkOrConvertType(store, last, &bx.Left, rt, autoNative) checkOrConvertType(store, last, &bx.Right, rt, autoNative) } + t = BoolType default: // do nothing }