Explorar o código

[parser] ignore incomplete ternary

closes #7471
Simon Krajewski %!s(int64=7) %!d(string=hai) anos
pai
achega
0ac6dd2114
Modificáronse 2 ficheiros con 16 adicións e 2 borrados
  1. 5 2
      src/syntax/grammar.mly
  2. 11 0
      tests/display/src/cases/Issue7471.hx

+ 5 - 2
src/syntax/grammar.mly

@@ -1305,8 +1305,11 @@ and expr_next' e1 = parser
 	| [< '(Binop op,_); e2 = secure_expr >] -> make_binop op e1 e2
 	| [< '(Unop op,p) when is_postfix e1 op; s >] ->
 		expr_next (EUnop (op,Postfix,e1), punion (pos e1) p) s
-	| [< '(Question,_); e2 = expr; '(DblDot,_); e3 = expr >] ->
-		(ETernary (e1,e2,e3),punion (pos e1) (pos e3))
+	| [< '(Question,_); e2 = expr; s >] ->
+		begin match s with parser
+		| [< '(DblDot,_); e3 = expr >] -> (ETernary (e1,e2,e3),punion (pos e1) (pos e3))
+		| [< >] -> if !in_display then e2 else serror()
+		end
 	| [< '(Kwd In,_); e2 = expr >] ->
 		make_binop OpIn e1 e2
 	| [< >] -> e1

+ 11 - 0
tests/display/src/cases/Issue7471.hx

@@ -0,0 +1,11 @@
+package cases;
+
+class Issue7471 extends DisplayTestCase {
+	/**
+	return "foo" == null ? "foo".{-1-}
+	**/
+	@:funcCode
+	function test() {
+		eq(true, hasField(fields(pos(1)), "length", "Int"));
+	}
+}