Merge branch 'bugfix/147-bool-comparison' into 'dev'
Resolve "Bool comparison" Closes #147 See merge request ligolang/ligo!413
This commit is contained in:
commit
eaba8e9857
@ -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
|
||||
|
@ -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 () ;
|
||||
|
5
src/test/contracts/eq_bool.ligo
Normal file
5
src/test/contracts/eq_bool.ligo
Normal file
@ -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
|
3
src/test/contracts/eq_bool.mligo
Normal file
3
src/test/contracts/eq_bool.mligo
Normal file
@ -0,0 +1,3 @@
|
||||
// Test conditional in CameLIGO
|
||||
|
||||
let main (a , b : bool * bool) = if a = b then 999 else 1
|
8
src/test/contracts/eq_bool.religo
Normal file
8
src/test/contracts/eq_bool.religo
Normal file
@ -0,0 +1,8 @@
|
||||
/* Test boolean comparison in ReasonLIGO */
|
||||
|
||||
let main = ((a , b) : (bool , bool)) =>
|
||||
if (a == b) {
|
||||
999;
|
||||
} else {
|
||||
1;
|
||||
};
|
@ -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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user