Skip to content

Commit 3a09840

Browse files
committed
refactor
1 parent e05abdf commit 3a09840

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

compiler/ml/error_message_utils.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ type type_clash_context =
9191
| Statement of type_clash_statement
9292
| ForLoopCondition
9393
94+
let context_to_string = function
95+
| Some WhileCondition -> "WhileCondition"
96+
| Some ForLoopCondition -> "ForLoopCondition"
97+
| Some AssertCondition -> "AssertCondition"
98+
| Some IfCondition -> "IfCondition"
99+
| Some (Statement _) -> "Statement"
100+
| Some (MathOperator _) -> "MathOperator"
101+
| Some ArrayValue -> "ArrayValue"
102+
| Some SetRecordField -> "SetRecordField"
103+
| Some MaybeUnwrapOption -> "MaybeUnwrapOption"
104+
| Some SwitchReturn -> "SwitchReturn"
105+
| Some TryReturn -> "TryReturn"
106+
| Some StringConcat -> "StringConcat"
107+
| Some FunctionArgument -> "FunctionArgument"
108+
| Some ComparisonOperator -> "ComparisonOperator"
109+
| Some IfReturn -> "IfReturn"
110+
| None -> "None"
111+
94112
let fprintf = Format.fprintf
95113
96114
let error_type_text ppf type_clash_context =

compiler/ml/typecore.ml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,14 +2381,14 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
23812381
[Vb.mk spat smatch]
23822382
sbody
23832383
in
2384-
type_function ~context:None ?in_function ~arity ~async loc
2385-
sexp.pexp_attributes env ty_expected l
2384+
type_function ?in_function ~arity ~async loc sexp.pexp_attributes env
2385+
ty_expected l
23862386
[Exp.case pat body]
23872387
| Pexp_fun
23882388
{arg_label = l; default = None; lhs = spat; rhs = sbody; arity; async} ->
23892389
let l = Asttypes.to_noloc l in
2390-
type_function ~context:None ?in_function ~arity ~async loc
2391-
sexp.pexp_attributes env ty_expected l
2390+
type_function ?in_function ~arity ~async loc sexp.pexp_attributes env
2391+
ty_expected l
23922392
[Ast_helper.Exp.case spat sbody]
23932393
| Pexp_apply {funct = sfunct; args = sargs; partial; transformed_jsx} ->
23942394
assert (sargs <> []);
@@ -2402,7 +2402,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
24022402
let total_app = not partial in
24032403
let context = type_clash_context_from_function sexp sfunct in
24042404
let args, ty_res, fully_applied =
2405-
match translate_unified_ops ~context:None env funct sargs with
2405+
match translate_unified_ops env funct sargs with
24062406
| Some (targs, result_type) -> (targs, result_type, true)
24072407
| None -> type_application ~context total_app env funct sargs
24082408
in
@@ -2500,8 +2500,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
25002500
exp_env = env;
25012501
}
25022502
| Pexp_construct (lid, sarg) ->
2503-
type_construct ~context:None env loc lid sarg ty_expected
2504-
sexp.pexp_attributes
2503+
type_construct env loc lid sarg ty_expected sexp.pexp_attributes
25052504
| Pexp_variant (l, sarg) -> (
25062505
(* Keep sharing *)
25072506
let ty_expected0 = instance env ty_expected in
@@ -2516,7 +2515,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
25162515
row_field_repr (List.assoc l row0.row_fields) )
25172516
with
25182517
| Rpresent (Some ty), Rpresent (Some ty0) ->
2519-
let arg = type_argument ~context env sarg ty ty0 in
2518+
let arg = type_argument ~context:None env sarg ty ty0 in
25202519
re
25212520
{
25222521
exp_desc = Texp_variant (l, Some arg);
@@ -2746,7 +2745,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
27462745
exp_env = env;
27472746
}
27482747
| Pexp_field (srecord, lid) ->
2749-
let record, label, _ = type_label_access ~context:None env srecord lid in
2748+
let record, label, _ = type_label_access env srecord lid in
27502749
let _, ty_arg, ty_res = instance_label false label in
27512750
unify_exp ~context:None env record ty_res;
27522751
rue
@@ -2759,9 +2758,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
27592758
exp_env = env;
27602759
}
27612760
| Pexp_setfield (srecord, lid, snewval) ->
2762-
let record, label, opath =
2763-
type_label_access ~context:None env srecord lid
2764-
in
2761+
let record, label, opath = type_label_access env srecord lid in
27652762
let ty_record = if opath = None then newvar () else record.exp_type in
27662763
let label_loc, label, newval, _ =
27672764
type_label_exp ~context:(Some SetRecordField) false env loc ty_record
@@ -2833,7 +2830,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
28332830
})
28342831
| Pexp_sequence (sexp1, sexp2) ->
28352832
let exp1 = type_statement ~context:None env sexp1 in
2836-
let exp2 = type_expect ~context env sexp2 ty_expected in
2833+
let exp2 = type_expect ~context:None env sexp2 ty_expected in
28372834
re
28382835
{
28392836
exp_desc = Texp_sequence (exp1, exp2);
@@ -2924,7 +2921,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
29242921
if separate then begin_def ();
29252922
(* TODO: What should this be?*)
29262923
let type_clash_context = None in
2927-
let arg = type_exp ~context env sarg in
2924+
let arg = type_exp ~context:None env sarg in
29282925
let gen =
29292926
if separate then (
29302927
end_def ();
@@ -3199,8 +3196,8 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
31993196
| Pexp_jsx_element _ ->
32003197
failwith "Pexp_jsx_element is expected to be transformed at this point"
32013198
3202-
and type_function ~context ?in_function ~arity ~async loc attrs env ty_expected_
3203-
l caselist =
3199+
and type_function ?in_function ~arity ~async loc attrs env ty_expected_ l
3200+
caselist =
32043201
let state = Warnings.backup () in
32053202
(* Disable Unerasable_optional_argument for uncurried functions *)
32063203
let unerasable_optional_argument =
@@ -3212,7 +3209,7 @@ and type_function ~context ?in_function ~arity ~async loc attrs env ty_expected_
32123209
| None -> ty_expected_
32133210
| Some arity ->
32143211
let fun_t = newty (Tarrow (l, newvar (), newvar (), Cok, Some arity)) in
3215-
unify_exp_types ~context loc env fun_t ty_expected_;
3212+
unify_exp_types ~context:None loc env fun_t ty_expected_;
32163213
fun_t
32173214
in
32183215
let loc_fun, ty_fun =
@@ -3267,8 +3264,8 @@ and type_function ~context ?in_function ~arity ~async loc attrs env ty_expected_
32673264
exp_env = env;
32683265
}
32693266
3270-
and type_label_access ~context env srecord lid =
3271-
let record = type_exp ~context ~recarg:Allowed env srecord in
3267+
and type_label_access env srecord lid =
3268+
let record = type_exp ~context:None ~recarg:Allowed env srecord in
32723269
let ty_exp = record.exp_type in
32733270
let opath =
32743271
try
@@ -3353,9 +3350,8 @@ and type_argument ~context ?recarg env sarg ty_expected' ty_expected =
33533350
(** This is ad-hoc translation for unifying specific primitive operations
33543351
See [Unified_ops] module for detailed explanation.
33553352
*)
3356-
and translate_unified_ops ~context (env : Env.t) (funct : Typedtree.expression)
3353+
and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
33573354
(sargs : sargs) : (targs * Types.type_expr) option =
3358-
ignore context;
33593355
match funct.exp_desc with
33603356
| Texp_ident (path, _, _) -> (
33613357
let entry = Hashtbl.find_opt Unified_ops.index_by_path (Path.name path) in
@@ -3684,9 +3680,7 @@ and type_application ~context total_app env funct (sargs : sargs) :
36843680
in
36853681
(targs, ret_t, fully_applied)
36863682
3687-
and type_construct ~context env loc lid sarg ty_expected attrs =
3688-
(* TODO: Fix this *)
3689-
ignore context;
3683+
and type_construct env loc lid sarg ty_expected attrs =
36903684
let opath =
36913685
try
36923686
let p0, p, _ = extract_concrete_variant env ty_expected in

0 commit comments

Comments
 (0)