From 4ec2161a5e4b1ac27fac90b45ae58af42e450947 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Thu, 1 Feb 2024 08:56:11 +0100 Subject: [PATCH] in_call_args needs to be on ctx.f also do some cleanup --- src/context/typecore.ml | 39 ++++++++++++++++--- src/typing/callUnification.ml | 12 +++--- src/typing/typeloadFields.ml | 9 +---- src/typing/typeloadFunction.ml | 22 ++--------- src/typing/typeloadModule.ml | 25 +----------- src/typing/typerDisplay.ml | 8 ++-- src/typing/typerEntry.ml | 25 +----------- .../Issue8488/compile-fail.hxml.stderr | 3 +- 8 files changed, 53 insertions(+), 90 deletions(-) diff --git a/src/context/typecore.ml b/src/context/typecore.ml index d1d92218ee2..a90e6eaed2d 100644 --- a/src/context/typecore.ml +++ b/src/context/typecore.ml @@ -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 = { @@ -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 = { @@ -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; @@ -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 = @@ -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 = diff --git a/src/typing/callUnification.ml b/src/typing/callUnification.ml index 43431c463fc..42891a4fed5 100644 --- a/src/typing/callUnification.ml +++ b/src/typing/callUnification.ml @@ -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 diff --git a/src/typing/typeloadFields.ml b/src/typing/typeloadFields.ml index 3a2ea621a81..0e86a0e4094 100644 --- a/src/typing/typeloadFields.ml +++ b/src/typing/typeloadFields.ml @@ -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 diff --git a/src/typing/typeloadFunction.ml b/src/typing/typeloadFunction.ml index 94bde4194b0..0a25439800c 100644 --- a/src/typing/typeloadFunction.ml +++ b/src/typing/typeloadFunction.ml @@ -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 = @@ -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 *) diff --git a/src/typing/typeloadModule.ml b/src/typing/typeloadModule.ml index 26c023309af..3a22dfbd9bf 100644 --- a/src/typing/typeloadModule.ml +++ b/src/typing/typeloadModule.ml @@ -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 = []; diff --git a/src/typing/typerDisplay.ml b/src/typing/typerDisplay.ml index 4bfed374310..93dca7ac502 100644 --- a/src/typing/typerDisplay.ml +++ b/src/typing/typerDisplay.ml @@ -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) @@ -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 -> diff --git a/src/typing/typerEntry.ml b/src/typing/typerEntry.ml index 8ab9afa7f5d..7a3f3e6d39c 100644 --- a/src/typing/typerEntry.ml +++ b/src/typing/typerEntry.ml @@ -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; diff --git a/tests/misc/projects/Issue8488/compile-fail.hxml.stderr b/tests/misc/projects/Issue8488/compile-fail.hxml.stderr index 51986db4846..bc7ce5e55b6 100644 --- a/tests/misc/projects/Issue8488/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue8488/compile-fail.hxml.stderr @@ -1,2 +1 @@ -Main.hx:5: characters 45-48 : String should be Int -Main.hx:5: characters 45-48 : ... For optional function argument 'a' \ No newline at end of file +Main.hx:5: characters 45-48 : String should be Int \ No newline at end of file