Răsfoiți Sursa

[typer] recover Error in assignments too

this might be a bit spicy, let's see...
closes #9171
Simon Krajewski 2 ani în urmă
părinte
comite
b24ae6839d

+ 12 - 1
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

+ 2 - 8
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

+ 1 - 2
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

+ 11 - 0
tests/misc/projects/Issue9171/Main.hx

@@ -0,0 +1,11 @@
+class C {
+	final x:Int;
+
+	function new() {
+		x = nonsense;
+	}
+}
+
+function main() {
+
+}

+ 3 - 0
tests/misc/projects/Issue9171/compile-fail.hxml

@@ -0,0 +1,3 @@
+-cp src
+-main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue9171/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:5: characters 7-15 : Unknown identifier : nonsense