Browse Source

[display] report interpolated string sub-expression position for `@type` (closes #5152)

Dan Korostelev 9 years ago
parent
commit
f6b9c0d86b

+ 4 - 4
src/typing/typer.ml

@@ -3753,8 +3753,8 @@ and handle_display ctx e_ast iscall with_type p =
 		) tl in
 		tl
 	in
-	let e = try
-		type_expr ctx e_ast with_type
+	let e,p = try
+		type_expr ctx e_ast with_type,p
 	with Error (Unknown_ident n,_) when not iscall ->
 		raise (Parser.TypePath ([n],None,false))
 	| Error (Unknown_ident "trace",_) ->
@@ -3765,11 +3765,11 @@ and handle_display ctx e_ast iscall with_type p =
 		with Not_found ->
 			raise err
 		end
-	| Display.DisplaySubExpression e ->
+	| Display.DisplaySubExpression ((_,p) as e) ->
 		ctx.in_display <- false;
 		let e = type_expr ctx e Value in
 		ctx.in_display <- true;
-		e
+		e,p
 	in
 	let e = match with_type with
 		| WithType t -> (try Codegen.AbstractCast.cast_or_unify_raise ctx t e e.epos with Error (Unify l,p) -> e)

+ 6 - 0
tests/misc/projects/Issue5152/Main.hx

@@ -0,0 +1,6 @@
+class Main {
+    static function main() {
+        var who = "world";
+        'hello, $who, how are you';
+    }
+}

+ 1 - 0
tests/misc/projects/Issue5152/compile.hxml

@@ -0,0 +1 @@
+--display Main.hx@87@type

+ 3 - 0
tests/misc/projects/Issue5152/compile.hxml.stderr

@@ -0,0 +1,3 @@
+<type p="d:\code\haxe\tests\misc\projects\issue5152\main.hx:4: characters 17-20">
+String
+</type>