Browse Source

[matcher] don't lose toplevel flag for null guards

closes #8213
Simon Krajewski 6 years ago
parent
commit
086de8288c
2 changed files with 15 additions and 2 deletions
  1. 2 2
      src/typing/matcher.ml
  2. 13 0
      tests/unit/src/unit/issues/Issue8213.hx

+ 2 - 2
src/typing/matcher.ml

@@ -1474,9 +1474,9 @@ module TexprConverter = struct
 									List.rev acc,dt
 							in
 							let conds,dt1 = loop2 [] dt1 in
-							let e_then = loop false params dt1 in
+							let e_then = loop toplevel params dt1 in
 							(fun () ->
-								let e_else = loop false params dt2 in
+								let e_else = loop toplevel params dt2 in
 								let e_cond = List.fold_left (fun e1 e2 -> binop OpBoolAnd e1 e2 ctx.t.tbool (punion e1.epos e2.epos)) (f_op e) conds in
 								mk (TIf(e_cond,e_then,Some e_else)) t_switch (punion e_then.epos e_else.epos)
 							)

+ 13 - 0
tests/unit/src/unit/issues/Issue8213.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue8213 extends unit.Test {
+	function test() {
+		var s = "hi";
+		switch s {
+			case null:
+			case "hi":
+			case "no":
+		}
+		utest.Assert.pass();
+	}
+}