diff --git a/src/typing/operators.ml b/src/typing/operators.ml index e203bac09e8..d96a509f630 100644 --- a/src/typing/operators.ml +++ b/src/typing/operators.ml @@ -9,6 +9,12 @@ open Calls open Fields open FieldAccess +let check_error ctx err p = match err with + | Module_not_found ([],name) when Diagnostics.error_in_diagnostics_run ctx.com p -> + DisplayToplevel.handle_unresolved_identifier ctx name p true + | _ -> + Common.located_display_error ctx.com (error_msg p err) + module BinopResult = struct type normal_binop = { @@ -547,7 +553,12 @@ let type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op with_type p = let type_assign ctx e1 e2 with_type p = let e1 = !type_access_ref ctx (fst e1) (snd e1) (MSet (Some e2)) with_type in - let type_rhs with_type = type_expr ctx e2 with_type in + let type_rhs with_type = try + type_expr ctx e2 with_type + with Error(e,p,_) -> + check_error ctx e p; + Texpr.Builder.make_null t_dynamic (pos e2) + in let assign_to e1 = let e2 = type_rhs (WithType.with_type e1.etype) in let e2 = AbstractCast.cast_or_unify ctx e1.etype e2 p in diff --git a/src/typing/typer.ml b/src/typing/typer.ml index 120b7704f07..d8cfd3f5968 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -124,12 +124,6 @@ let maybe_type_against_enum ctx f with_type iscall p = with Exit -> f() -let check_error ctx err p = match err with - | Module_not_found ([],name) when Diagnostics.error_in_diagnostics_run ctx.com p -> - DisplayToplevel.handle_unresolved_identifier ctx name p true - | _ -> - located_display_error ctx.com (error_msg p err) - (* ---------------------------------------------------------------------- *) (* PASS 3 : type expression & check structure *) @@ -1989,8 +1983,8 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) = | EThrow e -> let e = try type_expr ctx e WithType.value - with Error(e,p,_) -> - check_error ctx e p; + with Error(e,p',_) -> + check_error ctx e p'; Texpr.Builder.make_null t_dynamic p in mk (TThrow e) (mono_or_dynamic ctx with_type p) p diff --git a/tests/misc/projects/Issue8634/compile-fail.hxml.stderr b/tests/misc/projects/Issue8634/compile-fail.hxml.stderr index ce7df6f27d3..7fba5a66367 100644 --- a/tests/misc/projects/Issue8634/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue8634/compile-fail.hxml.stderr @@ -1,2 +1 @@ -Main.hx:4: characters 13-17 : Cannot use null as ternary condition -Main.hx:4: characters 13-17 : ... For function argument 'v' +Main.hx:4: characters 13-17 : Cannot use null as ternary condition \ No newline at end of file diff --git a/tests/misc/projects/Issue9171/Main.hx b/tests/misc/projects/Issue9171/Main.hx new file mode 100644 index 00000000000..14a31eb1a42 --- /dev/null +++ b/tests/misc/projects/Issue9171/Main.hx @@ -0,0 +1,11 @@ +class C { + final x:Int; + + function new() { + x = nonsense; + } +} + +function main() { + +} \ No newline at end of file diff --git a/tests/misc/projects/Issue9171/compile-fail.hxml b/tests/misc/projects/Issue9171/compile-fail.hxml new file mode 100644 index 00000000000..cafa855d377 --- /dev/null +++ b/tests/misc/projects/Issue9171/compile-fail.hxml @@ -0,0 +1,3 @@ +-cp src +-main Main +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue9171/compile-fail.hxml.stderr b/tests/misc/projects/Issue9171/compile-fail.hxml.stderr new file mode 100644 index 00000000000..c910f2b25a7 --- /dev/null +++ b/tests/misc/projects/Issue9171/compile-fail.hxml.stderr @@ -0,0 +1 @@ +Main.hx:5: characters 7-15 : Unknown identifier : nonsense \ No newline at end of file