2
0
Эх сурвалжийг харах

[matcher] fix exhaustiveness check for CompileTimeFinite types when there's no default case (closes #3665)

Simon Krajewski 10 жил өмнө
parent
commit
7d195a4183

+ 2 - 0
matcher.ml

@@ -936,6 +936,8 @@ let rec compile mctx stl pmat toplevel =
 				switch st_head cases
 				switch st_head cases
 			| _ when inf = RunTimeFinite && PMap.is_empty !all ->
 			| _ when inf = RunTimeFinite && PMap.is_empty !all ->
 				switch st_head cases
 				switch st_head cases
+			| [],_ when inf = CompileTimeFinite && PMap.is_empty !all ->
+				switch st_head cases
 			| [],_ when inf = Infinite && not mctx.need_val && toplevel ->
 			| [],_ when inf = Infinite && not mctx.need_val && toplevel ->
 				(* ignore exhaustiveness, but mark context so we do not generate @:exhaustive metadata *)
 				(* ignore exhaustiveness, but mark context so we do not generate @:exhaustive metadata *)
 				mctx.is_exhaustive <- false;
 				mctx.is_exhaustive <- false;

+ 18 - 0
tests/unit/src/unit/issues/Issue3665.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+@:enum
+private abstract E(Int) {
+	var A = 1;
+	var B = 2;
+}
+
+class Issue3665 extends Test {
+	function test() {
+		var x = A;
+		var x = switch (x) {
+			case A: 1;
+			case B: 2;
+		}
+		eq(1, x);
+	}
+}