فهرست منبع

[parser] don't lose `return` if we are displaying

closes #7066
Simon Krajewski 7 سال پیش
والد
کامیت
1cc14e9552
2فایلهای تغییر یافته به همراه28 افزوده شده و 1 حذف شده
  1. 1 1
      src/syntax/grammar.mly
  2. 27 0
      tests/display/src/cases/Issue7066.hx

+ 1 - 1
src/syntax/grammar.mly

@@ -1122,7 +1122,7 @@ and expr = parser
 					None
 		) in
 		(EIf (cond,e1,e2), punion p (match e2 with None -> pos e1 | Some e -> pos e))
-	| [< '(Kwd Return,p); e = popt expr >] -> (EReturn e, match e with None -> p | Some e -> punion p (pos e))
+	| [< '(Kwd Return,p); e = popt toplevel_expr >] -> (EReturn e, match e with None -> p | Some e -> punion p (pos e))
 	| [< '(Kwd Break,p) >] -> (EBreak,p)
 	| [< '(Kwd Continue,p) >] -> (EContinue,p)
 	| [< '(Kwd While,p1); '(POpen,_); cond = expr; '(PClose,_); s >] ->

+ 27 - 0
tests/display/src/cases/Issue7066.hx

@@ -0,0 +1,27 @@
+package cases;
+
+class Issue7066 extends DisplayTestCase {
+	/**
+	typedef Struct = {
+		?fieldA:Int,
+		?fieldB:String
+	}
+
+	class Main {
+		static function main() {}
+		function foo():Struct {
+			return {
+				fieldA: 5,
+				{-1-}
+			};
+		}
+	}
+	**/
+	function test() {
+		var results = fields(pos(1));
+		eq(1, results.length);
+		eq("fieldB", results[0].name);
+		eq("var", results[0].kind);
+		eq("Null<String>", results[0].type);
+	}
+}