Commit bc3850d6 authored by Julien Lopez's avatar Julien Lopez
Browse files

[TESTS][LAMBDA] match_simple_var and match_unused_branches passes; environment

	done for match
parent 07458a8d
......@@ -73,27 +73,30 @@ and parse_iface env l params fv nb iface = match params with
and parse_branches env l toptype brs res = match brs with
| (loc, p, e) :: rest ->
let brloc = caml_loc_to_cduce loc in
let br_locals, br_used = parse_match_value env l p toptype in
let list, br_locals, br_used = parse_match_value env l [] p toptype in
let line = Loc.start_line loc in
let cbegin = Loc.start_off loc - Loc.start_bol loc in
let cend = Loc.stop_off loc - Loc.start_bol loc in
let node = Patterns.make [] in
let _, _, br_body = _to_typed env br_locals e in
let fname = Loc.file_name loc in
let node =
(if not br_used then
(Printf.eprintf
"File %s, line %d, characters %d-%d:\nWarning: This branch is not used\n"
fname line cbegin cend; Patterns.make [])
else Patterns.make list) in
let b = { br_loc=brloc; br_used=br_used; br_ghost=false; br_vars_empty=[];
br_pat=node; br_body=br_body} in
let fname = Loc.file_name loc in
if not br_used then Printf.eprintf
"File %s, line %d, characters %d-%d:\nWarning: This branch is not used\n"
fname line cbegin cend;
parse_branches env l toptype rest (res @ [b])
| [] -> res
and parse_match_value env l p toptype = match p with
| MPair (_) -> l, false; (* TODO: Allow pairs in types *)
| MVar (_, mname, mtype) -> Locals.add mname (Locals.cardinal l) l,
is_subtype toptype mtype
| MInt (_) -> l, is_subtype toptype "Int"
| MString (_) -> l, is_subtype toptype "String"
and parse_match_value env l list p toptype = match p with
| MPair (_) -> list, l, false; (* TODO: Allow pairs in types *)
| MVar (_, mname, mtype) ->
let lsize = Locals.cardinal l in
(list @ [lsize, mname]), Locals.add mname lsize l, is_subtype toptype mtype
| MInt (_) -> list, l, is_subtype toptype "Int"
| MString (_) -> list, l, is_subtype toptype "String"
let to_typed expr =
let env, _, expr = _to_typed empty_toplevel Locals.empty expr in
......
1
File ./tests/eval/tests/match_unused_branches.test, line 1, characters 19-36:
Warning: This branch is not used
File ./tests/eval/tests/match_unused_branches.test, line 1, characters 37-52:
Warning: This branch is not used
(fun f x -> match x with | y : Int -> x+y).2
(fun f x : Int : Int -> match x : Int with | y : Int -> x).2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment