Skip to content

Commit 1bd14c0

Browse files
committed
refactor to handle type params (not supported)
1 parent 8c2989d commit 1bd14c0

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
@@ -1182,12 +1189,6 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
11821189
end
11831190
| Ppat_alias({ppat_desc=Ppat_type lid; ppat_attributes}, name) when Variant_coercion.has_res_pat_variant_spread_attribute ppat_attributes ->
11841191
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-
);
11911192
assert (constrs = None);
11921193

11931194
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
15231524
pat_extra = extra :: p.pat_extra}
15241525
in k p)
15251526
| 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
15331528
k { p with pat_extra =
15341529
(Tpat_type (path, lid), loc, sp.ppat_attributes) :: p.pat_extra }
15351530
| Ppat_type lid ->
@@ -4121,8 +4116,10 @@ let report_error env ppf = function
41214116
args (if args = 0 then "" else "s") arity
41224117
| Field_not_optional (name, typ) ->
41234118
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
41264123
41274124
41284125
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)