@@ -74,6 +74,7 @@ type error =
74
74
| Empty_record_literal
75
75
| Uncurried_arity_mismatch of type_expr * int * int
76
76
| Field_not_optional of string * type_expr
77
+ | Type_params_not_supported of Longident. t
77
78
exception Error of Location. t * Env. t * error
78
79
exception Error_forward of Location. error
79
80
@@ -598,9 +599,15 @@ let build_or_pat env loc lid =
598
599
let build_or_pat_for_variant_spread env loc lid expected_ty =
599
600
let path, decl = Typetexp. find_type env lid.loc lid.txt in
600
601
match decl with
601
- | {type_kind = Type_variant constructors } -> (
602
- (* TODO: Probably problematic that we don't account for type params here? *)
602
+ | {type_kind = Type_variant constructors ; type_params } -> (
603
+ if List. length type_params > 0 then raise ( Error (lid.loc, env, Type_params_not_supported lid.txt));
603
604
let ty = newty (Tconstr (path, [] , ref Mnil )) in
605
+ (try
606
+ Ctype. subtype env ty expected_ty ()
607
+ with
608
+ Ctype. Subtype (tr1 , tr2 ) ->
609
+ raise(Error (loc, env, Not_subtype (tr1, tr2)))
610
+ );
604
611
let gloc = {loc with Location. loc_ghost = true } in
605
612
let pats =
606
613
constructors
@@ -1179,12 +1186,6 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
1179
1186
end
1180
1187
| Ppat_alias ({ppat_desc =Ppat_type lid ; ppat_attributes} , name ) when Variant_coercion. has_res_pat_variant_spread_attribute ppat_attributes ->
1181
1188
let (_, p, ty) = build_or_pat_for_variant_spread ! env loc lid expected_ty in
1182
- (try
1183
- Ctype. subtype ! env ty expected_ty ()
1184
- with
1185
- Ctype. Subtype (tr1 , tr2 ) ->
1186
- raise(Error (loc, ! env, Not_subtype (tr1, tr2)))
1187
- );
1188
1189
assert (constrs = None );
1189
1190
1190
1191
let id = enter_variable ~is_as_variable: true loc name ty in
@@ -1519,13 +1520,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
1519
1520
pat_extra = extra :: p .pat_extra}
1520
1521
in k p)
1521
1522
| Ppat_type lid when Variant_coercion. has_res_pat_variant_spread_attribute sp.ppat_attributes ->
1522
- let (path, p, ty) = build_or_pat_for_variant_spread ! env loc lid expected_ty in
1523
- (try
1524
- Ctype. subtype ! env ty expected_ty ()
1525
- with
1526
- Ctype. Subtype (tr1 , tr2 ) ->
1527
- raise(Error (loc, ! env, Not_subtype (tr1, tr2)))
1528
- );
1523
+ let (path, p, _ty) = build_or_pat_for_variant_spread ! env loc lid expected_ty in
1529
1524
k { p with pat_extra =
1530
1525
(Tpat_type (path, lid), loc, sp.ppat_attributes) :: p.pat_extra }
1531
1526
| Ppat_type lid ->
@@ -4100,8 +4095,10 @@ let report_error env ppf = function
4100
4095
args (if args = 0 then " " else " s" ) arity
4101
4096
| Field_not_optional (name , typ ) ->
4102
4097
fprintf ppf
4103
- " Field @{<info>%s@} is not optional in type %a. Use without ?" name
4104
- type_expr typ
4098
+ " Field @{<info>%s@} is not optional in type %a. Use without ?" name
4099
+ type_expr typ
4100
+ | Type_params_not_supported lid ->
4101
+ fprintf ppf " The type %a@ has type parameters, but type parameters is not supported here." longident lid
4105
4102
4106
4103
4107
4104
let super_report_error_no_wrap_printing_env = report_error
0 commit comments