Browse Source

[typer] recover Error in EThrow

closes #10170
Simon Krajewski 2 years ago
parent
commit
dc7f0c3dd0

+ 6 - 1
src/typing/typer.ml

@@ -1987,7 +1987,12 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
 	| ETry (e1,catches) ->
 		type_try ctx e1 catches with_type p
 	| EThrow e ->
-		let e = type_expr ctx e WithType.value in
+		let e = try
+			type_expr ctx e WithType.value
+		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
 	| ENew (t,el) ->
 		type_new ctx t el with_type false p

+ 7 - 0
tests/misc/projects/Issue10170/Main.hx

@@ -0,0 +1,7 @@
+function f():Int {
+	throw invalid;
+}
+
+function main() {
+
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:2: characters 8-15 : Unknown identifier : invalid