Browse Source

anything throws (closes #5774)

Simon Krajewski 8 years ago
parent
commit
4229da6990
2 changed files with 42 additions and 41 deletions
  1. 4 4
      src/optimization/analyzerTexpr.ml
  2. 38 37
      tests/optimization/src/TestAnalyzer.hx

+ 4 - 4
src/optimization/analyzerTexpr.ml

@@ -84,10 +84,10 @@ let map_values ?(allow_control_flow=true) f e =
 
 let can_throw e =
 	let rec loop e = match e.eexpr with
-		| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ | TBlock _ -> ()
-		| TCall _ | TNew _ | TThrow _ | TCast(_,Some _) -> raise Exit
-		| TField _ | TArray _ -> raise Exit (* sigh *)
-		| _ -> Type.iter loop e
+		| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ -> ()
+		| TCall _ | TNew _ | TThrow _ | TCast _ | TField _ | TArray _ | TBinop _ | TObjectDecl _ | TArrayDecl _ | TUnop _
+		| TVar _ | TFor _ | TWhile _ | TReturn _ -> raise Exit
+		| TParenthesis _ | TMeta _  | TBreak | TContinue | TEnumParameter _ | TBlock _ | TIf _ | TSwitch _ | TTry _ -> Type.iter loop e
 	in
 	try
 		loop e; false

+ 38 - 37
tests/optimization/src/TestAnalyzer.hx

@@ -448,17 +448,18 @@ class TestAnalyzer extends TestBase {
 		assertEquals(1, a);
 	}
 
-	function testTry1() {
-		var a = 1;
-		try {
-
-		} catch(e:Dynamic) {
-			assertEqualsConst(1, a);
-			a = 2;
-			assertEqualsConst(2, a);
-		}
-		assertEqualsConst(1, a);
-	}
+	// No longer possible, see #5774
+	// function testTry1() {
+	// 	var a = 1;
+	// 	try {
+
+	// 	} catch(e:Dynamic) {
+	// 		assertEqualsConst(1, a);
+	// 		a = 2;
+	// 		assertEqualsConst(2, a);
+	// 	}
+	// 	assertEqualsConst(1, a);
+	// }
 
 	function testTry2() {
 		var a = 1;
@@ -503,32 +504,32 @@ class TestAnalyzer extends TestBase {
 		assertEqualsConst(1, a);
 	}
 
-	function testTry5() {
-		var a = 1;
-		try {
-			throws();
-			a = 2;
-			a = 1;
-		} catch (e:Dynamic) {
-
-		}
-		assertEqualsConst(1, a);
-	}
-
-	function testTry6() {
-		var a = 1;
-		try {
-			a = 2;
-			throws();
-			a = 1;
-			a = 2;
-		} catch (e:String) {
-
-		} catch (e:Dynamic) {
-
-		}
-		assertEqualsConst(2, a);
-	}
+	// function testTry5() {
+	// 	var a = 1;
+	// 	try {
+	// 		throws();
+	// 		a = 2;
+	// 		a = 1;
+	// 	} catch (e:Dynamic) {
+
+	// 	}
+	// 	assertEqualsConst(1, a);
+	// }
+
+	// function testTry6() {
+	// 	var a = 1;
+	// 	try {
+	// 		a = 2;
+	// 		throws();
+	// 		a = 1;
+	// 		a = 2;
+	// 	} catch (e:String) {
+
+	// 	} catch (e:Dynamic) {
+
+	// 	}
+	// 	assertEqualsConst(2, a);
+	// }
 
 	function testTry7() {
 		var a = 1;