Skip to content

Commit

Permalink
[typer] recover Error in assignments too
Browse files Browse the repository at this point in the history
this might be a bit spicy, let's see...
closes HaxeFoundation#9171
  • Loading branch information
Simn committed Mar 28, 2023
1 parent dc7f0c3 commit b24ae68
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
13 changes: 12 additions & 1 deletion src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue8634/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/misc/projects/Issue9171/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class C {
final x:Int;

function new() {
x = nonsense;
}
}

function main() {

}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue9171/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-cp src
-main Main
--interp
1 change: 1 addition & 0 deletions tests/misc/projects/Issue9171/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main.hx:5: characters 7-15 : Unknown identifier : nonsense

0 comments on commit b24ae68

Please sign in to comment.