Prechádzať zdrojové kódy

[matcher] never omit explicit `default` even when the type is considered finite (closes #3649)

Simon Krajewski 10 rokov pred
rodič
commit
6e526b7ada
2 zmenil súbory, kde vykonal 28 pridanie a 1 odobranie
  1. 1 1
      matcher.ml
  2. 27 0
      tests/unit/src/unit/issues/Issue3649.hx

+ 1 - 1
matcher.ml

@@ -929,7 +929,7 @@ let rec compile mctx stl pmat toplevel =
 			let dt = match def,cases with
 			| _ when List.exists (fun (c,_) -> match c.c_def with CFields _ -> true | _ -> false) cases ->
 				switch st_head cases
-			| _ when not inf && PMap.is_empty !all ->
+			| [],_ when not inf && PMap.is_empty !all ->
 				switch st_head cases
 			| [],_ when inf && not mctx.need_val && toplevel ->
 				(* ignore exhaustiveness, but mark context so we do not generate @:exhaustive metadata *)

+ 27 - 0
tests/unit/src/unit/issues/Issue3649.hx

@@ -0,0 +1,27 @@
+package unit.issues;
+
+@:enum
+abstract HttpStatus(Int) {
+	var NotFound = 404;
+	var MethodNotAllowed = 405;
+}
+
+class Issue3649 extends Test {
+
+	function test() {
+		eq("Not found", print(NotFound));
+		eq("Method not allowed", print(MethodNotAllowed));
+		eq("Unknown", print(cast 12));
+	}
+
+	static function print(status:HttpStatus) {
+		return switch(status) {
+			case NotFound:
+				'Not found';
+			case MethodNotAllowed:
+				'Method not allowed';
+			default:
+				'Unknown';
+		}
+	}
+}