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

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

Aleksandr Kuzmenko 5 жил өмнө
parent
commit
c14dd2fd66

+ 1 - 0
extra/CHANGES.txt

@@ -6,6 +6,7 @@
 
 	Bugfixes:
 
+	all : fixed `switch` typing error for arrow functions with `Void` return type (#9813)
 	php : fixed false detection of `catch` vars in anonymous functions as captured from outer scope
 	php : fixed return type of extern definition for `fseek` function
 	cs,java : fixed generation of `@:generic` classes with anonymous functions (#9799)

+ 5 - 1
src/typing/matcher.ml

@@ -1680,7 +1680,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);
+	}
+}