empty for collection loop

This commit is contained in:
Lesenechal Remi 2019-10-28 18:53:40 +01:00
parent 37570c6a40
commit e77f3e4903
3 changed files with 27 additions and 1 deletions

View File

@ -1189,7 +1189,7 @@ and simpl_for_collect : Raw.for_collect -> (_ -> expression result) result = fun
(* STEP 9 *)
let final_sequence = match reassign_sequence with
(* None case means that no variables were captured *)
| None -> e_let_in ("#COMPILER#folded_record", None) fold (e_skip ())
| None -> e_skip ()
| Some seq -> e_let_in ("#COMPILER#folded_record", None) fold seq in
return_statement @@ final_sequence

View File

@ -46,6 +46,27 @@ function for_collection_set (var nee : unit) : (int * string) is block {
end
} with (acc, st)
// function for_collection_assignements_in_ifs (var nee : unit) : int is block {
// var acc : int := 0 ;
// var myset : set(int) := set 1 ; 2 ; 3 end ;
// for x : int in set myset
// begin
// if (x=1) then
// acc := acc + x ;
// else
// acc := acc + 10 ;
// end
// } with acc
function for_collection_empty (var nee : unit) : int is block {
var acc : int := 0 ;
var myset : set(int) := set 1 ; 2 ; 3 end ;
for x : int in set myset
begin
skip ;
end
} with acc
// function for_collection_map (var nee : unit) : (int * string) is block {
// var acc : int := 0 ;
// var st : string := "" ;

View File

@ -674,6 +674,11 @@ let loop () : unit result =
let expected = e_pair (e_int 6) (e_string "totototo") in
expect_eq program "for_collection_set" input expected
in
let%bind () =
let input = e_unit () in
let expected = (e_int 0) in
expect_eq program "for_collection_empty" input expected
in
ok ()
(* Don't know how to assert parse error happens in this test framework