Browse Source

[parser] allow ECheckType in unsafe casts if cast-expression has parentheses (closes #3950)

Simon Krajewski 10 years ago
parent
commit
a2821832d5
2 changed files with 11 additions and 0 deletions
  1. 3 0
      parser.ml
  2. 8 0
      tests/unit/src/unit/issues/Issue3950.hx

+ 3 - 0
parser.ml

@@ -1215,6 +1215,9 @@ and expr = parser
 		| [< '(POpen,pp); e = expr; s >] ->
 			(match s with parser
 			| [< '(Comma,_); t = parse_complex_type; '(PClose,p2); s >] -> expr_next (ECast (e,Some t),punion p1 p2) s
+			| [< t = parse_type_hint; '(PClose,p2); s >] ->
+				let ep = EParenthesis (ECheckType(e,t),punion p1 p2), punion p1 p2 in
+				expr_next (ECast (ep,None),punion p1 (pos ep)) s
 			| [< '(PClose,p2); s >] ->
 				let ep = expr_next (EParenthesis(e),punion pp p2) s in
 				expr_next (ECast (ep,None),punion p1 (pos ep)) s

+ 8 - 0
tests/unit/src/unit/issues/Issue3950.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue3950 extends Test {
+	function test() {
+		var s = cast ("foo" : String);
+		eq("foo", s);
+	}
+}