Skip to content

Commit

Permalink
[parser] fix binop position spanning (closes #6399)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jun 29, 2017
1 parent 35ae6be commit 5c34c87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/syntax/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/display/src/cases/Issue6396.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 29 additions & 0 deletions tests/display/src/cases/Issue6399.hx
Original file line number Diff line number Diff line change
@@ -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)));
}
}

0 comments on commit 5c34c87

Please sign in to comment.