Browse Source

[parser] allow `try` without `catch` again and wave it trough in the typer

Simon Krajewski 10 years ago
parent
commit
740b2ed187

+ 1 - 4
parser.ml

@@ -1221,10 +1221,7 @@ and expr = parser
 			Display e -> display (EWhile (cond,e,NormalWhile),punion p1 (pos e)))
 	| [< '(Kwd Do,p1); e = expr; '(Kwd While,_); '(POpen,_); cond = expr; '(PClose,_); s >] -> (EWhile (cond,e,DoWhile),punion p1 (pos e))
 	| [< '(Kwd Switch,p1); e = expr; '(BrOpen,_); cases , def = parse_switch_cases e []; '(BrClose,p2); s >] -> (ESwitch (e,cases,def),punion p1 p2)
-	| [< '(Kwd Try,p1); e = expr; cl = plist (parse_catch e); >] ->
-		(match cl with
-			| [] -> error (Custom "Expected catch after try") p1
-			| _ -> (ETry (e,cl),p1))
+	| [< '(Kwd Try,p1); e = expr; cl = plist (parse_catch e); >] -> (ETry (e,cl),p1)
 	| [< '(IntInterval i,p1); e2 = expr >] -> make_binop OpInterval (EConst (Int i),p1) e2
 	| [< '(Kwd Untyped,p1); e = expr >] -> (EUntyped e,punion p1 (pos e))
 	| [< '(Dollar v,p); s >] -> expr_next (EConst (Ident ("$"^v)),p) s

+ 0 - 5
tests/misc/projects/Issue3699/MainTry.hx

@@ -1,5 +0,0 @@
-class MainTry {
-	static public function main() {
-		try { "foo"; }
-	}
-}

+ 0 - 1
tests/misc/projects/Issue3699/compile-try-fail.hxml

@@ -1 +0,0 @@
---run MainTry

+ 0 - 1
tests/misc/projects/Issue3699/compile-try-fail.hxml.stderr

@@ -1 +0,0 @@
-MainTry.hx:3: characters 2-5 : Expected catch after try

+ 2 - 0
typer.ml

@@ -3171,6 +3171,8 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| EContinue ->
 		if not ctx.in_loop then display_error ctx "Continue outside loop" p;
 		mk TContinue t_dynamic p
+	| ETry (e1,[]) ->
+		type_expr ctx e1 with_type
 	| ETry (e1,catches) ->
 		let e1 = type_expr ctx e1 with_type in
 		let rec check_unreachable cases t p = match cases with