Browse Source

add some more null tests

Simon Krajewski 10 years ago
parent
commit
0d698379ca
2 changed files with 83 additions and 0 deletions
  1. 1 0
      tests/optimization/run.hxml
  2. 82 0
      tests/optimization/src/TestNullChecker.hx

+ 1 - 0
tests/optimization/run.hxml

@@ -7,6 +7,7 @@
 
 --next
 -main TestNullChecker
+-D analyzer-check-null
 --interp
 
 --next

+ 82 - 0
tests/optimization/src/TestNullChecker.hx

@@ -69,6 +69,76 @@ class TestNullChecker extends TestBase {
 		@:analyzer(testIsNotNull) ns;
 	}
 
+	function testReturn1() {
+		var ns = getNullString();
+		if (ns == null) {
+			return;
+		}
+		@:analyzer(testIsNotNull) ns;
+	}
+
+	function testReturn2() {
+		var ns = getNullString();
+		if (ns != null) {
+
+		} else {
+			return;
+		}
+		@:analyzer(testIsNotNull) ns;
+	}
+
+	// doesn't work yet due to || transformation
+	//function testReturn3() {
+		//var ns = getNullString();
+		//if (ns == null || getTrue()) {
+			//return;
+		//}
+		//@:analyzer(testIsNotNull) ns;
+	//}
+
+	function testReturn4() {
+		var ns = getNullString();
+		if (ns != null && getTrue()) {
+
+		} else {
+			return;
+		}
+		@:analyzer(testIsNull) ns;
+	}
+
+	function testBreak() {
+		var ns = getNullString();
+		while (true) {
+			if (ns == null) {
+				break;
+			}
+			@:analyzer(testIsNotNull) ns;
+		}
+		@:analyzer(testIsNull) ns;
+	}
+
+	function testContinue() {
+		var ns = getNullString();
+		while (true) {
+			if (getTrue()) {
+				break; // to terminate
+			}
+			if (ns == null) {
+				continue;
+			}
+			@:analyzer(testIsNotNull) ns;
+		}
+		@:analyzer(testIsNull) ns;
+	}
+
+	function testThrow() {
+		var ns = getNotNullString();
+		if (ns == null) {
+			throw false;
+		}
+		@:analyzer(testIsNotNull) ns;
+	}
+
 	function getString() {
 		return "foo";
 	}
@@ -76,4 +146,16 @@ class TestNullChecker extends TestBase {
 	function getNullString():Null<String> {
 		return null;
 	}
+
+	function getNotNullString():Null<String> {
+		return "foo";
+	}
+
+	function getTrue() {
+		return true;
+	}
+
+	function getFalse() {
+		return false;
+	}
 }