@@ -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
@@ -1182,12 +1189,6 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
1182
1189
end
1183
1190
| Ppat_alias ({ppat_desc =Ppat_type lid ; ppat_attributes} , name ) when Variant_coercion. has_res_pat_variant_spread_attribute ppat_attributes ->
1184
1191
let (_, p, ty) = build_or_pat_for_variant_spread ! env loc lid expected_ty in
1185
- (try
1186
- Ctype. subtype ! env ty expected_ty ()
1187
- with
1188
- Ctype. Subtype (tr1 , tr2 ) ->
1189
- raise(Error (loc, ! env, Not_subtype (tr1, tr2)))
1190
- );
1191
1192
assert (constrs = None );
1192
1193
1193
1194
let id = enter_variable ~is_as_variable: true loc name ty in
@@ -1523,13 +1524,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
1523
1524
pat_extra = extra :: p .pat_extra}
1524
1525
in k p)
1525
1526
| Ppat_type lid when Variant_coercion. has_res_pat_variant_spread_attribute sp.ppat_attributes ->
1526
- let (path, p, ty) = build_or_pat_for_variant_spread ! env loc lid expected_ty in
1527
- (try
1528
- Ctype. subtype ! env ty expected_ty ()
1529
- with
1530
- Ctype. Subtype (tr1 , tr2 ) ->
1531
- raise(Error (loc, ! env, Not_subtype (tr1, tr2)))
1532
- );
1527
+ let (path, p, _ty) = build_or_pat_for_variant_spread ! env loc lid expected_ty in
1533
1528
k { p with pat_extra =
1534
1529
(Tpat_type (path, lid), loc, sp.ppat_attributes) :: p.pat_extra }
1535
1530
| Ppat_type lid ->
@@ -4121,8 +4116,10 @@ let report_error env ppf = function
4121
4116
args (if args = 0 then " " else " s" ) arity
4122
4117
| Field_not_optional (name , typ ) ->
4123
4118
fprintf ppf
4124
- " Field @{<info>%s@} is not optional in type %a. Use without ?" name
4125
- type_expr typ
4119
+ " Field @{<info>%s@} is not optional in type %a. Use without ?" name
4120
+ type_expr typ
4121
+ | Type_params_not_supported lid ->
4122
+ fprintf ppf " The type %a@ has type parameters, but type parameters is not supported here." longident lid
4126
4123
4127
4124
4128
4125
let super_report_error_no_wrap_printing_env = report_error
0 commit comments