浏览代码

do not error on missing null matches

Simon Krajewski 12 年之前
父节点
当前提交
92f0cbdffa
共有 3 个文件被更改,包括 12 次插入11 次删除
  1. 1 0
      codegen.ml
  2. 1 1
      matcher.ml
  3. 10 10
      tests/unit/TestMatch.hx

+ 1 - 0
codegen.ml

@@ -1343,6 +1343,7 @@ let check_local_vars_init e =
 				| DTBind(_,dt) -> fdt dt
 				| DTGoto _ -> ()
 			in
+			Array.iter fdt dt.dt_dt_lookup;
 			join vars !cvars
 		(* mark all reachable vars as initialized, since we don't exit the block  *)
 		| TBreak | TContinue | TReturn None ->

+ 1 - 1
matcher.ml

@@ -726,7 +726,7 @@ let rec is_explicit_null = function
 
 let rec all_ctors mctx t =
 	let h = ref PMap.empty in
-	if is_explicit_null t then h := PMap.add (CConst TNull) Ast.null_pos !h;
+	(* if is_explicit_null t then h := PMap.add (CConst TNull) Ast.null_pos !h; *)
 	match follow t with
 	| TAbstract({a_path = [],"Bool"},_) ->
 		h := PMap.add (CConst(TBool true)) Ast.null_pos !h;

+ 10 - 10
tests/unit/TestMatch.hx

@@ -337,16 +337,16 @@ class TestMatch extends Test {
 		eq("Unmatched patterns: [_,false,_]", getErrorMessage(switch [1, true, "foo"] {
 			case [_, true, _]:
 		}));
-		var x:Null<Bool> = true;
-		eq("Unmatched patterns: null", getErrorMessage(switch x {
-			case true:
-			case false:
-		}));
-		var t:Null<Tree<String>> = null;
-		eq("Unmatched patterns: null", getErrorMessage(switch t {
-			case Leaf(_):
-			case Node(_):
-		}));		
+		//var x:Null<Bool> = true;
+		//eq("Unmatched patterns: null", getErrorMessage(switch x {
+			//case true:
+			//case false:
+		//}));
+		//var t:Null<Tree<String>> = null;
+		//eq("Unmatched patterns: null", getErrorMessage(switch t {
+			//case Leaf(_):
+			//case Node(_):
+		//}));
 	}
 
 	function testInvalidBinding() {