Skip to content

Commit 4675cc1

Browse files
committed
refactor to handle type params (not supported)
1 parent 8a5deab commit 4675cc1

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

jscomp/ml/typecore.ml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type error =
7474
| Empty_record_literal
7575
| Uncurried_arity_mismatch of type_expr * int * int
7676
| Field_not_optional of string * type_expr
77+
| Type_params_not_supported of Longident.t
7778
exception Error of Location.t * Env.t * error
7879
exception Error_forward of Location.error
7980

@@ -598,9 +599,15 @@ let build_or_pat env loc lid =
598599
let build_or_pat_for_variant_spread env loc lid expected_ty =
599600
let path, decl = Typetexp.find_type env lid.loc lid.txt in
600601
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));
603604
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+
);
604611
let gloc = {loc with Location.loc_ghost = true} in
605612
let pats =
606613
constructors
@@ -1179,12 +1186,6 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
11791186
end
11801187
| Ppat_alias({ppat_desc=Ppat_type lid; ppat_attributes}, name) when Variant_coercion.has_res_pat_variant_spread_attribute ppat_attributes ->
11811188
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-
);
11881189
assert (constrs = None);
11891190

11901191
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
15191520
pat_extra = extra :: p.pat_extra}
15201521
in k p)
15211522
| 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
15291524
k { p with pat_extra =
15301525
(Tpat_type (path, lid), loc, sp.ppat_attributes) :: p.pat_extra }
15311526
| Ppat_type lid ->
@@ -4100,8 +4095,10 @@ let report_error env ppf = function
41004095
args (if args = 0 then "" else "s") arity
41014096
| Field_not_optional (name, typ) ->
41024097
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
41054102
41064103
41074104
let super_report_error_no_wrap_printing_env = report_error

jscomp/ml/typecore.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type error =
107107
| Empty_record_literal
108108
| Uncurried_arity_mismatch of type_expr * int * int
109109
| Field_not_optional of string * type_expr
110+
| Type_params_not_supported of Longident.t
110111
exception Error of Location.t * Env.t * error
111112
exception Error_forward of Location.error
112113

0 commit comments

Comments
 (0)