@@ -1558,11 +1558,11 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env sp
15581558 | None -> None
15591559 | Some rest_pat ->
15601560 (* Extract type annotation and binding name from rest pattern *)
1561- let rest_type_lid, rest_name =
1561+ let rest_type_lid, rest_name, rest_type_args_syntax =
15621562 match rest_pat.ppat_desc with
15631563 | Ppat_constraint ({ppat_desc = Ppat_var name } , cty ) -> (
15641564 match cty.ptyp_desc with
1565- | Ptyp_constr (lid , [] ) -> (lid, name)
1565+ | Ptyp_constr (lid , type_args ) -> (lid, name, type_args )
15661566 | _ ->
15671567 raise
15681568 (Error (rest_pat.ppat_loc, ! env, Record_rest_invalid_type )))
@@ -1661,12 +1661,30 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env sp
16611661 (Ident. name rest_label.ld_id, rest_type_lid.txt) )))
16621662 rest_labels
16631663 | [] -> () );
1664+ let rest_type_args =
1665+ match rest_type_args_syntax with
1666+ | [] -> List. map (fun _ -> newvar () ) rest_decl.type_params
1667+ | args ->
1668+ let n_args = List. length args in
1669+ let n_params = List. length rest_decl.type_params in
1670+ if n_args <> n_params then
1671+ raise
1672+ (Typetexp. Error
1673+ ( rest_type_lid.loc,
1674+ ! env,
1675+ Typetexp. Type_arity_mismatch
1676+ (rest_type_lid.txt, n_params, n_args) ));
1677+ List. map
1678+ (fun sty ->
1679+ let cty, force =
1680+ Typetexp. transl_simple_type_delayed ! env sty
1681+ in
1682+ pattern_force := force :: ! pattern_force;
1683+ cty.ctyp_type)
1684+ args
1685+ in
16641686 let rest_type_expr =
1665- newgenty
1666- (Tconstr
1667- ( rest_path,
1668- List. map (fun _ -> newvar () ) rest_decl.type_params,
1669- ref Mnil ))
1687+ newgenty (Tconstr (rest_path, rest_type_args, ref Mnil ))
16701688 in
16711689 let rest_ident =
16721690 enter_variable rest_pat.ppat_loc rest_name rest_type_expr
0 commit comments