diff options
| author | Alasdair Armstrong | 2017-07-27 13:22:09 +0100 |
|---|---|---|
| committer | Alasdair Armstrong | 2017-07-27 13:22:09 +0100 |
| commit | 55cef4bf4baf94c5984b02aea6d53abcf82ba1ea (patch) | |
| tree | 1c6bc0ae5e5a5944a4c433e4e67726aa802f9539 | |
| parent | c1a431aa50a65704a349174ecf7b9017ff87c570 (diff) | |
Fixed bug with pattern synonyms in Cons and List patterns
| -rw-r--r-- | src/type_check.ml | 8 | ||||
| -rw-r--r-- | test/typecheck/pass/cons_pattern_synonym.sail | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/type_check.ml b/src/type_check.ml index 320a4a34..74e00784 100644 --- a/src/type_check.ml +++ b/src/type_check.ml @@ -1802,8 +1802,8 @@ and bind_pat env (P_aux (pat_aux, (l, ())) as pat) (Typ_aux (typ_aux, _) as typ) | P_wild -> annot_pat P_wild typ, env | P_cons (hd_pat, tl_pat) -> begin - match typ_aux with - | Typ_app (f, [Typ_arg_aux (Typ_arg_typ ltyp, _)]) when Id.compare f (mk_id "list") = 0 -> + match Env.expand_synonyms env typ with + | Typ_aux (Typ_app (f, [Typ_arg_aux (Typ_arg_typ ltyp, _)]), _) when Id.compare f (mk_id "list") = 0 -> let hd_pat, env = bind_pat env hd_pat ltyp in let tl_pat, env = bind_pat env tl_pat typ in annot_pat (P_cons (hd_pat, tl_pat)) typ, env @@ -1811,8 +1811,8 @@ and bind_pat env (P_aux (pat_aux, (l, ())) as pat) (Typ_aux (typ_aux, _) as typ) end | P_list pats -> begin - match typ_aux with - | Typ_app (f, [Typ_arg_aux (Typ_arg_typ ltyp, _)]) when Id.compare f (mk_id "list") = 0 -> + match Env.expand_synonyms env typ with + | Typ_aux (Typ_app (f, [Typ_arg_aux (Typ_arg_typ ltyp, _)]), _) when Id.compare f (mk_id "list") = 0 -> let rec process_pats env = function | [] -> [], env | (pat :: pats) -> diff --git a/test/typecheck/pass/cons_pattern_synonym.sail b/test/typecheck/pass/cons_pattern_synonym.sail new file mode 100644 index 00000000..f5b26294 --- /dev/null +++ b/test/typecheck/pass/cons_pattern_synonym.sail @@ -0,0 +1,7 @@ +typedef ty = list<(bit[8])> + +function bool foo ((ty) l) = + switch l { + case _ :: _ -> false + case _ -> true + }
\ No newline at end of file |
