Browse Source

[parser] fix binop position spanning (closes #6399)

Simon Krajewski 8 years ago
parent
commit
5c34c8710f

+ 2 - 1
src/syntax/parser.mly

@@ -183,7 +183,8 @@ let reify in_macro =
 		| Regexp (r,o) -> mk_enum "Constant" "CRegexp" [(EConst (String r),p);(EConst (String o),p)] p
 	in
 	let rec to_binop o p =
-		let op n = mk_enum "Binop" n [] p in
+		let pmin = {p with pmax = p.pmin} in
+		let op n = mk_enum "Binop" n [] pmin in
 		match o with
 		| OpAdd -> op "OpAdd"
 		| OpMult -> op "OpMult"

+ 2 - 2
tests/display/src/cases/Issue6396.hx

@@ -14,7 +14,7 @@ class Issue6396 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq(range(1, 2), position(pos(2)));
-		eq("String", type(pos(2)));
+		eq(range(1, 2), position(pos(3)));
+		eq("String", type(pos(3)));
 	}
 }

+ 29 - 0
tests/display/src/cases/Issue6399.hx

@@ -0,0 +1,29 @@
+package cases;
+
+class Issue6399 extends DisplayTestCase {
+	/**
+	class Main {
+		public static function main() {}
+
+		macro function foo({-1-}name{-2-}:String, {-3-}struct{-4-}:Expr, {-5-}defaults{-6-}:Expr) {
+			return macro {
+				if ($str{-7-}uct.$n{-8-}ame == null) $str{-9-}uct.$n{-10-}ame = $defa{-11-}ults.$n{-12-}ame;
+			}
+		}
+	}
+	**/
+	function test() {
+		for (i in [8, 10, 12]) {
+			eq(range(1, 2), position(pos(i)));
+			eq("String", type(pos(i)));
+		}
+
+		for (i in [7, 9]) {
+			eq(range(3, 4), position(pos(i)));
+			eq("Dynamic", type(pos(i)));
+		}
+
+		eq(range(5, 6), position(pos(11)));
+		eq("Dynamic", type(pos(11)));
+	}
+}