Răsfoiți Sursa

[matcher] don't unify switch type with the expected type,
if it's allowed to be `Void` (fixes #9813)

Aleksandr Kuzmenko 5 ani în urmă
părinte
comite
e6d21742f0
2 a modificat fișierele cu 20 adăugiri și 1 ștergeri
  1. 5 1
      src/typing/matcher.ml
  2. 15 0
      tests/unit/src/unit/issues/Issue9813.hx

+ 5 - 1
src/typing/matcher.ml

@@ -1683,7 +1683,11 @@ module Match = struct
 		end;
 		let e = try
 			let t_switch = infer_switch_type() in
-			(match tmono with Some t -> unify ctx t_switch t p | _ -> ());
+			(match tmono with
+			| Some t when allow_min_void && ExtType.is_void (follow t) -> ()
+			| Some t -> unify ctx t_switch t p
+			| _ -> ()
+			);
 			TexprConverter.to_texpr ctx t_switch match_debug with_type dt
 		with TexprConverter.Not_exhaustive ->
 			error "Unmatched patterns: _" p;

+ 15 - 0
tests/unit/src/unit/issues/Issue9813.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+class Issue9813 extends unit.Test {
+	var my : Int;
+	var cb : Int->Void;
+
+	function test() {
+		cb = n -> switch n {
+			case 1: my = 2;
+			case _: my = 3;
+		};
+		cb(12);
+		eq(3, my);
+	}
+}