Browse Source

handle Exit when parsing interpolated expression (closes #6826)

Dan Korostelev 7 years ago
parent
commit
c00559c995

+ 8 - 2
src/typing/typer.ml

@@ -2748,8 +2748,14 @@ and format_string ctx s p =
 		let scode = String.sub s (pos + 1) slen in
 		if warn_escape then warn (pos + 1) slen;
 		min := !min + 2;
-		if slen > 0 then
-			add_expr (ParserEntry.parse_expr_string ctx.com.defines scode { p with pmin = !pmin + pos + 2; pmax = !pmin + send + 1 } error true) slen;
+		if slen > 0 then begin
+			let e =
+				let ep = { p with pmin = !pmin + pos + 2; pmax = !pmin + send + 1 } in
+				try ParserEntry.parse_expr_string ctx.com.defines scode ep error true
+				with Exit -> error "Invalid interpolated expression" ep
+			in
+			add_expr e slen
+		end;
 		min := !min + 1;
 		parse (send + 1) (send + 1)
 	in

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

@@ -0,0 +1,7 @@
+class Main
+{
+  public static function main()
+  {
+    trace('Hello ${ } world!');
+  }
+}

+ 2 - 0
tests/misc/projects/Issue6826/compile-fail.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 2 - 0
tests/misc/projects/Issue6826/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:5: characters 20-21 : Invalid interpolated expression
+Main.hx:5: characters 20-21 : For function argument 'v'