Browse Source

[matcher] adjust to exhaustiveness spec

closes #7333
Simon Krajewski 7 years ago
parent
commit
e26f0ee231

+ 4 - 4
src/typing/matcher.ml

@@ -1368,9 +1368,9 @@ module TexprConverter = struct
 						let e_subject,unmatched,kind,finiteness = all_ctors ctx e_subject cases in
 						let unmatched = ExtList.List.filter_map (unify_constructor ctx params e_subject.etype) unmatched in
 						let loop toplevel params dt =
-							try Some (loop toplevel params dt)
+							try Some (loop false params dt)
 							with Not_exhaustive -> match with_type,finiteness with
-								| WithType.NoValue,Infinite -> None
+								| WithType.NoValue,Infinite when toplevel -> None
 								| _,CompileTimeFinite when unmatched = [] -> None
 								| _ when ctx.com.display.DisplayMode.dms_error_policy = DisplayMode.EPIgnore -> None
 								| _ -> report_not_exhaustive e_subject unmatched
@@ -1396,10 +1396,10 @@ module TexprConverter = struct
 							| [],RunTimeFinite ->
 								None
 							| _ ->
-								loop false params default
+								loop toplevel params default
 						in
 						let cases = ExtList.List.filter_map (fun (cons,dt,params) ->
-							let eo = loop false params dt in
+							let eo = loop toplevel params dt in
 							begin match eo with
 								| None -> None
 								| Some e -> Some (List.map (Constructor.to_texpr ctx match_debug) (List.sort Constructor.compare cons),e)

+ 13 - 0
tests/misc/projects/Issue7333/Main.hx

@@ -0,0 +1,13 @@
+enum MyEnum {
+    A(a:Int);
+}
+
+class Test
+{
+    public static function main()
+    {
+        switch(A(123)) {
+            case A(0): 0;
+        };
+    }
+}

+ 2 - 0
tests/misc/projects/Issue7333/compile-fail.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue7333/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:9: characters 16-22 : Unmatched patterns: A(_)

+ 1 - 0
tests/unit/src/unit/issues/Issue6133.hx

@@ -11,6 +11,7 @@ class Issue6133 extends unit.Test {
 		var foo = new Foo();
 		switch foo {
 			case { b: 5 }:
+			case { b: _ }:
 		}
 	}
 }