Skip to content

Commit

Permalink
in_call_args needs to be on ctx.f
Browse files Browse the repository at this point in the history
also do some cleanup
  • Loading branch information
Simn committed Feb 1, 2024
1 parent 9fb411e commit 4ec2161
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 90 deletions.
39 changes: 33 additions & 6 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ and typer_expr = {
mutable bypass_accessor : int;
mutable with_type_stack : WithType.t list;
mutable call_argument_stack : expr list list;
mutable in_call_args : bool;
mutable in_overload_call_args : bool;
}

and typer_field = {
Expand All @@ -158,6 +156,8 @@ and typer_field = {
mutable untyped : bool;
mutable meta : metadata;
mutable in_display : bool;
mutable in_call_args : bool;
mutable in_overload_call_args : bool;
}

and typer = {
Expand All @@ -167,7 +167,7 @@ and typer = {
g : typer_globals;
mutable m : typer_module;
c : typer_class;
e : typer_expr;
mutable e : typer_expr;
f : typer_field;
mutable pass : typer_pass;
mutable type_params : type_params;
Expand Down Expand Up @@ -202,6 +202,33 @@ module TyperManager = struct
pass = PBuildClass;
} in
ctx

let create_ctx_f cf =
{
locals = PMap.empty;
curfield = cf;
vthis = None;
untyped = false;
meta = [];
in_display = false;
in_overload_call_args = false;
in_call_args = false;
}

let create_ctx_e () =
{
ret = t_dynamic;
curfun = FunStatic;
opened = [];
in_function = false;
monomorphs = {
perfunction = [];
};
in_loop = false;
bypass_accessor = 0;
with_type_stack = [];
call_argument_stack = [];
}
end

type field_host =
Expand Down Expand Up @@ -320,16 +347,16 @@ let raise_with_type_error ?(depth = 0) msg p =

let raise_or_display ctx l p =
if ctx.f.untyped then ()
else if ctx.e.in_call_args then raise (WithTypeError (make_error (Unify l) p))
else if ctx.f.in_call_args then raise (WithTypeError (make_error (Unify l) p))
else display_error_ext ctx.com (make_error (Unify l) p)

let raise_or_display_error ctx err =
if ctx.f.untyped then ()
else if ctx.e.in_call_args then raise (WithTypeError err)
else if ctx.f.in_call_args then raise (WithTypeError err)
else display_error_ext ctx.com err

let raise_or_display_message ctx msg p =
if ctx.e.in_call_args then raise_with_type_error msg p
if ctx.f.in_call_args then raise_with_type_error msg p
else display_error ctx.com msg p

let unify ctx t1 t2 p =
Expand Down
12 changes: 6 additions & 6 deletions src/typing/callUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ let unify_call_args ctx el args r callp inline force_inline in_overload =
end
in
let restore =
let in_call_args = ctx.e.in_call_args in
let in_overload_call_args = ctx.e.in_overload_call_args in
ctx.e.in_call_args <- true;
ctx.e.in_overload_call_args <- in_overload;
let in_call_args = ctx.f.in_call_args in
let in_overload_call_args = ctx.f.in_overload_call_args in
ctx.f.in_call_args <- true;
ctx.f.in_overload_call_args <- in_overload;
(fun () ->
ctx.e.in_call_args <- in_call_args;
ctx.e.in_overload_call_args <- in_overload_call_args;
ctx.f.in_call_args <- in_call_args;
ctx.f.in_overload_call_args <- in_overload_call_args;
)
in
let el = try loop el args with exc -> restore(); raise exc; in
Expand Down
9 changes: 1 addition & 8 deletions src/typing/typeloadFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,7 @@ let create_typer_context_for_field ctx cctx fctx cff =
DeprecationCheck.check_is ctx.com ctx.m.curmod ctx.c.curclass.cl_meta cff.cff_meta (fst cff.cff_name) cff.cff_meta (snd cff.cff_name);
let ctx = {
ctx with
f = {
locals = PMap.empty;
curfield = null_field;
vthis = None;
untyped = false;
meta = [];
in_display = false;
};
f = TyperManager.create_ctx_f null_field;
pass = PBuildClass; (* will be set later to PTypeExpr *)
type_params = if fctx.is_static && not fctx.is_abstract_member && not (Meta.has Meta.LibType cctx.tclass.cl_meta) (* TODO: remove this *) then [] else ctx.type_params;
} in
Expand Down
22 changes: 4 additions & 18 deletions src/typing/typeloadFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@ open Error
open FunctionArguments

let save_field_state ctx =
let old_ret = ctx.e.ret in
let old_fun = ctx.e.curfun in
let old_opened = ctx.e.opened in
let old_monos = ctx.e.monomorphs.perfunction in
let old_in_function = ctx.e.in_function in
let old_e = ctx.e in
ctx.e <- TyperManager.create_ctx_e ();
let locals = ctx.f.locals in
(fun () ->
ctx.f.locals <- locals;
ctx.e.ret <- old_ret;
ctx.e.curfun <- old_fun;
ctx.e.opened <- old_opened;
ctx.e.monomorphs.perfunction <- old_monos;
ctx.e.in_function <- old_in_function;
ctx.e <- old_e;
)

let type_function_params ctx fd host fname p =
Expand Down Expand Up @@ -191,14 +184,7 @@ let add_constructor ctx c force_constructor p =
let t = spawn_monomorph ctx.e p in
let r = make_lazy ctx t (fun r ->
let ctx = { ctx with
f = {
locals = PMap.empty;
curfield = cf;
vthis = None;
untyped = false;
meta = [];
in_display = false;
};
f = TyperManager.create_ctx_f cf;
pass = PConnectField;
} in
ignore (follow cfsup.cf_type); (* make sure it's typed *)
Expand Down
25 changes: 2 additions & 23 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -708,29 +708,8 @@ let create_typer_context_for_module ctx m = {
get_build_infos = (fun() -> None);
tthis = t_dynamic;
};
f = {
locals = PMap.empty;
curfield = null_field;
vthis = None;
untyped = false;
meta = [];
in_display = false;
};
e = {
ret = t_dynamic;
curfun = FunStatic;
opened = [];
in_function = false;
monomorphs = {
perfunction = [];
};
in_loop = false;
bypass_accessor = 0;
with_type_stack = [];
call_argument_stack = [];
in_call_args = false;
in_overload_call_args = false;
};
f = TyperManager.create_ctx_f null_field;
e = TyperManager.create_ctx_e ();
allow_inline = true;
allow_transform = true;
type_params = [];
Expand Down
8 changes: 4 additions & 4 deletions src/typing/typerDisplay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ and display_expr ctx e_ast e dk mode with_type p =
raise_fields fields (CRField(item,e.epos,iterator,keyValueIterator)) (make_subject None (DisplayPosition.display_position#with_pos p))

let handle_display ctx e_ast dk mode with_type =
let old = ctx.f.in_display,ctx.e.in_call_args in
let old = ctx.f.in_display,ctx.f.in_call_args in
ctx.f.in_display <- true;
ctx.e.in_call_args <- false;
ctx.f.in_call_args <- false;
let tpair t =
let ct = CompletionType.from_type (get_import_status ctx) t in
(t,ct)
Expand Down Expand Up @@ -658,9 +658,9 @@ let handle_display ctx e_ast dk mode with_type =
print_endline (Printf.sprintf "cast expr:\n%s" (s_expr_ast true "" (s_type (print_context())) e));
end;
ctx.f.in_display <- fst old;
ctx.e.in_call_args <- snd old;
ctx.f.in_call_args <- snd old;
let f () = display_expr ctx e_ast e dk mode with_type p in
if ctx.e.in_overload_call_args then begin
if ctx.f.in_overload_call_args then begin
try
f()
with DisplayException de ->
Expand Down
25 changes: 2 additions & 23 deletions src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,8 @@ let create com macros =
tthis = t_dynamic;
get_build_infos = (fun() -> None);
};
f = {
locals = PMap.empty;
curfield = null_field;
vthis = None;
untyped = false;
meta = [];
in_display = false;
};
e = {
ret = t_dynamic;
curfun = FunStatic;
opened = [];
in_function = false;
monomorphs = {
perfunction = [];
};
in_loop = false;
bypass_accessor = 0;
with_type_stack = [];
call_argument_stack = [];
in_call_args = false;
in_overload_call_args = false;
};
f = TyperManager.create_ctx_f null_field;
e = TyperManager.create_ctx_e ();
pass = PBuildModule;
macro_depth = 0;
allow_inline = true;
Expand Down
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue8488/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Main.hx:5: characters 45-48 : String should be Int
Main.hx:5: characters 45-48 : ... For optional function argument 'a'
Main.hx:5: characters 45-48 : String should be Int

0 comments on commit 4ec2161

Please sign in to comment.