浏览代码

use proper unification for switch because it can fail (closes #5268)

Simon Krajewski 9 年之前
父节点
当前提交
d77b598491

+ 1 - 1
src/typing/matcher.ml

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

+ 19 - 0
tests/misc/projects/Issue5268/Main.hx

@@ -0,0 +1,19 @@
+import haxe.ds.Option;
+
+class Main {
+    public static function main() {
+        return switch outcome() {
+            case Some(v):
+                var value = switch v {
+                    case 1: 1;
+                    case m: return None;
+                }
+                value;
+            case None:
+                2;
+        }
+    }
+
+    static function outcome()
+        return Some(1);
+}

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

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

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

@@ -0,0 +1,2 @@
+Main.hx:5: lines 5-14 : Int should be haxe.ds.Option<Unknown<0>>
+Main.hx:5: lines 5-14 : Int should be haxe.ds.Option<Unknown<0>>