Browse Source

[parser] fix more positions (closes #6416) (closes #6417)

Simon Krajewski 8 years ago
parent
commit
69ca7f6709

+ 8 - 8
src/syntax/parser.mly

@@ -168,10 +168,12 @@ let make_is e (t,p_t) p p_is =
 let reify in_macro =
 let reify in_macro =
 	let cur_pos = ref None in
 	let cur_pos = ref None in
 	let mk_enum ename n vl p =
 	let mk_enum ename n vl p =
-		let constr = (EConst (Ident n),p) in
+		(* We don't want the position of the call expression to span the entire call (#6396). *)
+		let pmin = {p with pmax = p.pmin} in
+		let constr = (EConst (Ident n),pmin) in
 		match vl with
 		match vl with
 		| [] -> constr
 		| [] -> constr
-		| _ -> (ECall (constr,vl),p)
+		| _ -> (ECall (constr,vl),pmin)
 	in
 	in
 	let to_const c p =
 	let to_const c p =
 		let cst n v = mk_enum "Constant" n [EConst (String v),p] p in
 		let cst n v = mk_enum "Constant" n [EConst (String v),p] p in
@@ -183,8 +185,7 @@ let reify in_macro =
 		| Regexp (r,o) -> mk_enum "Constant" "CRegexp" [(EConst (String r),p);(EConst (String o),p)] p
 		| Regexp (r,o) -> mk_enum "Constant" "CRegexp" [(EConst (String r),p);(EConst (String o),p)] p
 	in
 	in
 	let rec to_binop o p =
 	let rec to_binop o p =
-		let pmin = {p with pmax = p.pmin} in
-		let op n = mk_enum "Binop" n [] pmin in
+		let op n = mk_enum "Binop" n [] p in
 		match o with
 		match o with
 		| OpAdd -> op "OpAdd"
 		| OpAdd -> op "OpAdd"
 		| OpMult -> op "OpMult"
 		| OpMult -> op "OpMult"
@@ -284,6 +285,7 @@ let reify in_macro =
 		(* to_obj ["type",to_ctype t p;"pos",to_pos p] p *)
 		(* to_obj ["type",to_ctype t p;"pos",to_pos p] p *)
 		to_ctype (t,p) p
 		to_ctype (t,p) p
 	and to_fun f p =
 	and to_fun f p =
+		let p = {p with pmax = p.pmin} in
 		let farg ((n,_),o,_,t,e) p =
 		let farg ((n,_),o,_,t,e) p =
 			let fields = [
 			let fields = [
 				"name", to_string n p;
 				"name", to_string n p;
@@ -366,9 +368,7 @@ let reify in_macro =
 	and to_expr e _ =
 	and to_expr e _ =
 		let p = snd e in
 		let p = snd e in
 		let expr n vl =
 		let expr n vl =
-			(* We don't want the position of the call expression to span the entire call (#6396). *)
-			let pmin = {p with pmax = p.pmin} in
-			let e = mk_enum "ExprDef" n vl pmin in
+			let e = mk_enum "ExprDef" n vl p in
 			to_obj [("expr",e);("pos",to_pos p)] p
 			to_obj [("expr",e);("pos",to_pos p)] p
 		in
 		in
 		let loop e = to_expr e (snd e) in
 		let loop e = to_expr e (snd e) in
@@ -415,7 +415,7 @@ let reify in_macro =
 		| EFunction (name,f) ->
 		| EFunction (name,f) ->
 			let name = match name with
 			let name = match name with
 				| None ->
 				| None ->
-					to_null p
+					to_null null_pos
 				| Some name ->
 				| Some name ->
 					if ExtString.String.starts_with name "inline_$" then begin
 					if ExtString.String.starts_with name "inline_$" then begin
 						let real_name = (String.sub name 7 (String.length name - 7)) in
 						let real_name = (String.sub name 7 (String.length name - 7)) in

+ 21 - 0
tests/display/src/cases/Issue6416.hx

@@ -0,0 +1,21 @@
+package cases;
+
+class Issue6416 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {}
+
+		macro function foo(e:haxe.macro.Expr) {
+			switch (e) {
+				case macro $i{{-1-}f{-2-}oo{-3-}}:
+					f{-4-}oo;
+			}
+		}
+	}
+	**/
+	function test() {
+		eq(range(1, 3), position(pos(2)));
+		eq(range(1, 3), position(pos(4)));
+		eq("String", type(pos(2)));
+	}
+}

+ 17 - 0
tests/display/src/cases/Issue6417.hx

@@ -0,0 +1,17 @@
+package cases;
+
+class Issue6417 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {}
+
+		macro function foo({-1-}body{-2-}:Expr) {
+			macro function() $bo{-3-}dy;
+		}
+	}
+	**/
+	function test() {
+		eq(range(1, 2), position(pos(3)));
+		eq("Dynamic", type(pos(3)));
+	}
+}