Skip to content

Commit e6f9d7c

Browse files
committed
refactor to handle type params (not supported)
1 parent a77e7b1 commit e6f9d7c

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

jscomp/ml/typecore.ml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type error =
7676
| Empty_record_literal
7777
| Uncurried_arity_mismatch of type_expr * int * int
7878
| Field_not_optional of string * type_expr
79+
| Type_params_not_supported of Longident.t
7980
exception Error of Location.t * Env.t * error
8081
exception Error_forward of Location.error
8182

@@ -594,9 +595,15 @@ let build_or_pat env loc lid =
594595
let build_or_pat_for_variant_spread env loc lid expected_ty =
595596
let path, decl = Typetexp.find_type env lid.loc lid.txt in
596597
match decl with
597-
| {type_kind = Type_variant constructors} -> (
598-
(* TODO: Probably problematic that we don't account for type params here? *)
598+
| {type_kind = Type_variant constructors; type_params} -> (
599+
if List.length type_params > 0 then raise (Error (lid.loc, env, Type_params_not_supported lid.txt));
599600
let ty = newty (Tconstr (path, [], ref Mnil)) in
601+
(try
602+
Ctype.subtype env ty expected_ty ()
603+
with
604+
Ctype.Subtype (tr1, tr2) ->
605+
raise(Error(loc, env, Not_subtype(tr1, tr2)))
606+
);
600607
let gloc = {loc with Location.loc_ghost = true} in
601608
let pats =
602609
constructors
@@ -1169,12 +1176,6 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
11691176
end
11701177
| Ppat_alias({ppat_desc=Ppat_type lid; ppat_attributes}, name) when Variant_coercion.has_res_pat_variant_spread_attribute ppat_attributes ->
11711178
let (_, p, ty) = build_or_pat_for_variant_spread !env loc lid expected_ty in
1172-
(try
1173-
Ctype.subtype !env ty expected_ty ()
1174-
with
1175-
Ctype.Subtype (tr1, tr2) ->
1176-
raise(Error(loc, !env, Not_subtype(tr1, tr2)))
1177-
);
11781179
assert (constrs = None);
11791180

11801181
let id = enter_variable ~is_as_variable:true loc name ty in
@@ -1509,13 +1510,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
15091510
pat_extra = extra :: p.pat_extra}
15101511
in k p)
15111512
| Ppat_type lid when Variant_coercion.has_res_pat_variant_spread_attribute sp.ppat_attributes ->
1512-
let (path, p, ty) = build_or_pat_for_variant_spread !env loc lid expected_ty in
1513-
(try
1514-
Ctype.subtype !env ty expected_ty ()
1515-
with
1516-
Ctype.Subtype (tr1, tr2) ->
1517-
raise(Error(loc, !env, Not_subtype(tr1, tr2)))
1518-
);
1513+
let (path, p, _ty) = build_or_pat_for_variant_spread !env loc lid expected_ty in
15191514
k { p with pat_extra =
15201515
(Tpat_type (path, lid), loc, sp.ppat_attributes) :: p.pat_extra }
15211516
| Ppat_type lid ->
@@ -4160,6 +4155,8 @@ let report_error env ppf = function
41604155
fprintf ppf
41614156
"Field @{<info>%s@} is not optional in type %a. Use without ?" name
41624157
type_expr typ
4158+
| Type_params_not_supported lid ->
4159+
fprintf ppf "The type %a@ has type parameters, but type parameters is not supported here." longident lid
41634160
41644161
41654162
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
@@ -111,6 +111,7 @@ type error =
111111
| Empty_record_literal
112112
| Uncurried_arity_mismatch of type_expr * int * int
113113
| Field_not_optional of string * type_expr
114+
| Type_params_not_supported of Longident.t
114115
exception Error of Location.t * Env.t * error
115116
exception Error_forward of Location.error
116117

jscomp/runtime/release.ninja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/cam
2525
o runtime/caml_exceptions.cmi : cc runtime/caml_exceptions.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2626
o runtime/caml_float.cmj : cc_cmi runtime/caml_float.res | runtime/caml_float.cmi runtime/caml_float_extern.cmj
2727
o runtime/caml_float.cmi : cc runtime/caml_float.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
28-
o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
28+
o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
2929
o runtime/caml_format.cmi : cc runtime/caml_format.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3030
o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj runtime/js.cmj
3131
o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
@@ -41,7 +41,7 @@ o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.res | runtime/caml_array_extern
4141
o runtime/caml_md5.cmi : cc runtime/caml_md5.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4242
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
4343
o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
44-
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
44+
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
4545
o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4646
o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj runtime/js.cmj
4747
o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
@@ -58,7 +58,7 @@ o runtime/caml_bigint_extern.cmi runtime/caml_bigint_extern.cmj : cc runtime/cam
5858
o runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj : cc runtime/caml_external_polyfill.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
5959
o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6060
o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
61-
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj
61+
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
6262
o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6363
o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6464
o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj

0 commit comments

Comments
 (0)