Browse Source

unused pattern message fix by @Simn (closes #4957)

Dan Korostelev 9 years ago
parent
commit
08a989271c

+ 6 - 6
matcher.ml

@@ -1245,6 +1245,12 @@ module TexprConverter = struct
 					| (con1 :: _),con2 :: _ -> Constructor.compare con1 con2
 					| (con1 :: _),con2 :: _ -> Constructor.compare con1 con2
 					| _ -> -1
 					| _ -> -1
 				) cases in
 				) cases in
+				let e_default = match unmatched,finiteness with
+					| [],RunTimeFinite ->
+						None
+					| _ ->
+						loop false params default
+				in
 				let cases = ExtList.List.filter_map (fun (cons,dt,params) ->
 				let cases = ExtList.List.filter_map (fun (cons,dt,params) ->
 					let eo = loop false params dt in
 					let eo = loop false params dt in
 					begin match eo with
 					begin match eo with
@@ -1252,12 +1258,6 @@ module TexprConverter = struct
 						| Some e -> Some (List.map (Constructor.to_texpr ctx match_debug dt.dt_pos) (List.sort Constructor.compare cons),e)
 						| Some e -> Some (List.map (Constructor.to_texpr ctx match_debug dt.dt_pos) (List.sort Constructor.compare cons),e)
 					end
 					end
 				) cases in
 				) cases in
-				let e_default = match unmatched,finiteness with
-					| [],RunTimeFinite ->
-						None
-					| _ ->
-						loop false params default
-				in
 				let e_subject = match kind with
 				let e_subject = match kind with
 					| SKValue -> e_subject
 					| SKValue -> e_subject
 					| SKEnum -> if match_debug then mk_name_call e_subject else mk_index_call e_subject
 					| SKEnum -> if match_debug then mk_name_call e_subject else mk_index_call e_subject

+ 18 - 0
tests/misc/projects/Issue4957/Main.hx

@@ -0,0 +1,18 @@
+enum E {
+    A(i:Int);
+    B;
+}
+
+class Main {
+    static function main() {
+        var e = B;
+
+        switch (e) { // Correct: Unmatched patterns: B
+            case A(10):
+        }
+
+        var v = switch (e) { // Wrong: Unmatched patterns: A(_)
+            case A(10): null;
+        }
+    }
+}

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

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

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

@@ -0,0 +1,2 @@
+Main.hx:10: characters 16-17 : Unmatched patterns: B
+Main.hx:14: characters 24-25 : Unmatched patterns: B