diff --git a/src/passes/8-compiler/compiler_type.ml b/src/passes/8-compiler/compiler_type.ml index 3ff7691ae..3e8690bdc 100644 --- a/src/passes/8-compiler/compiler_type.ml +++ b/src/passes/8-compiler/compiler_type.ml @@ -11,6 +11,7 @@ module Ty = struct open Script_typed_ir + let bool_k = Bool_key None let nat_k = Nat_key None let tez_k = Mutez_key None let int_k = Int_key None @@ -62,7 +63,7 @@ module Ty = struct match tb with | TC_unit -> fail (not_comparable "unit") | TC_void -> fail (not_comparable "void") - | TC_bool -> fail (not_comparable "bool") + | TC_bool -> return bool_k | TC_nat -> return nat_k | TC_mutez -> return tez_k | TC_int -> return int_k diff --git a/src/passes/operators/helpers.ml b/src/passes/operators/helpers.ml index c8e993452..f248b1dc4 100644 --- a/src/passes/operators/helpers.ml +++ b/src/passes/operators/helpers.ml @@ -112,6 +112,7 @@ module Typer = struct List.exists (eq_2 (a , b)) [ t_int () ; t_nat () ; + t_bool () ; t_mutez () ; t_string () ; t_bytes () ; diff --git a/src/test/contracts/eq_bool.ligo b/src/test/contracts/eq_bool.ligo new file mode 100644 index 000000000..92e0e9e1b --- /dev/null +++ b/src/test/contracts/eq_bool.ligo @@ -0,0 +1,5 @@ +function main (const a : bool; const b : bool) : int is + block { + var result : int := 27; + if a = b then result := 999 else result := 1 + } with result diff --git a/src/test/contracts/eq_bool.mligo b/src/test/contracts/eq_bool.mligo new file mode 100644 index 000000000..6869d5dfd --- /dev/null +++ b/src/test/contracts/eq_bool.mligo @@ -0,0 +1,3 @@ +// Test conditional in CameLIGO + +let main (a , b : bool * bool) = if a = b then 999 else 1 diff --git a/src/test/contracts/eq_bool.religo b/src/test/contracts/eq_bool.religo new file mode 100644 index 000000000..5674d49b5 --- /dev/null +++ b/src/test/contracts/eq_bool.religo @@ -0,0 +1,8 @@ +/* Test boolean comparison in ReasonLIGO */ + +let main = ((a , b) : (bool , bool)) => + if (a == b) { + 999; + } else { + 1; + }; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index bcf47d740..f79d3e8e3 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1205,6 +1205,30 @@ let condition_religo () : unit result = ] in ok () +let eq_bool_common program = + let%bind _ = + bind_map_list (fun ( a , b , expected ) -> + expect_eq program "main" (e_pair (e_bool a) (e_bool b)) (e_int expected)) + [ + ( false , false , 999 ) ; + ( false , true , 1 ) ; + ( true , false , 1 ) ; + ( true , true , 999 ) ; + ] + in + ok () + +let eq_bool () : unit result = + let%bind program = type_file "./contracts/eq_bool.ligo" in + eq_bool_common program + +let eq_bool_mligo () : unit result = + let%bind program = mtype_file "./contracts/eq_bool.mligo" in + eq_bool_common program + +let eq_bool_religo () : unit result = + let%bind program = retype_file "./contracts/eq_bool.religo" in + eq_bool_common program let condition_simple () : unit result = let%bind program = type_file "./contracts/condition-simple.ligo" in @@ -2272,6 +2296,9 @@ let main = test_suite "Integration (End to End)" [ test "condition (ligo)" condition ; test "condition (mligo)" condition_mligo ; test "condition (religo)" condition_religo ; + test "eq bool (ligo)" eq_bool ; + test "eq bool (mligo)" eq_bool_mligo ; + test "eq bool (religo)" eq_bool_religo ; test "shadow" shadow ; test "annotation" annotation ; test "multiple parameters" multiple_parameters ;