Ver código fonte

do not force toplevel null checks in patterns even if the subject is Null<T> (closes #3054)

Simon Krajewski 11 anos atrás
pai
commit
5493c1ac3d
2 arquivos alterados com 36 adições e 1 exclusões
  1. 7 1
      matcher.ml
  2. 29 0
      tests/unit/issues/Issue3054.hx

+ 7 - 1
matcher.ml

@@ -941,7 +941,13 @@ let rec compile mctx stl pmat toplevel =
 				raise (Not_exhaustive(any,st_head))
 			| [],_ ->
 				let pl = PMap.foldi (fun cd p acc -> (mk_con_pat cd [] t_dynamic p) :: acc) !all [] in
-				raise (Not_exhaustive(collapse_pattern pl,st_head))
+				(* toplevel null can be omitted because the French dig runtime errors (issue #3054) *)
+				if toplevel && (match pl with
+					| [{p_def = PCon ({c_def = (CConst TNull)},_)}] -> true
+					| _ -> false) then
+						switch st_head cases
+				else
+					raise (Not_exhaustive(collapse_pattern pl,st_head))
 			| def,[] ->
 				compile mctx st_tail def false
 			| def,_ ->

+ 29 - 0
tests/unit/issues/Issue3054.hx

@@ -0,0 +1,29 @@
+package unit.issues;
+
+private enum MyEnum {
+	A;
+	B;
+}
+
+private enum MyOtherEnum {
+	A(e:Null<MyEnum>);
+	B;
+}
+
+
+class Issue3054 extends Test {
+	function test() {
+		var myValue:Null<MyEnum> = A;
+		switch(myValue) {
+			case A:
+			case B:
+		}
+
+		var myOtherValue:Null<MyOtherEnum> = B;
+		t(unit.TestType.typeError(switch(myOtherValue) {
+			case A(A):
+			case A(B):
+			case B:
+		}));
+	}
+}