Browse Source

don't ignore unification errors on switch for abstracts
fixes #8579

Aleksandr Kuzmenko 6 years ago
parent
commit
c65439d03c

+ 1 - 9
src/typing/matcher.ml

@@ -238,15 +238,7 @@ module Pattern = struct
 					PatConstructor(con_type_expr mt e.epos,[])
 					PatConstructor(con_type_expr mt e.epos,[])
 				| _ ->
 				| _ ->
 					let pat = check_expr e in
 					let pat = check_expr e in
-					begin try
-						Type.unify e.etype t
-					with (Unify_error l) ->
-						(* Hack: Allow matching the underlying type against its abstract. *)
-						begin match follow e.etype with
-							| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) && type_iseq t (Abstract.get_underlying_type a tl) -> ()
-							| _ -> raise_or_display ctx l p
-						end
-					end;
+					unify ctx e.etype t p;
 					pat
 					pat
 		in
 		in
 		let handle_ident s p =
 		let handle_ident s p =

+ 14 - 0
tests/misc/projects/Issue8579/Main.hx

@@ -0,0 +1,14 @@
+abstract A(Int) {
+	public static final instance:A = cast 42;
+}
+
+class Main {
+	static function main() {
+		switch 42 {
+			case A.instance:
+				trace("YES");
+			case _:
+				trace("NO");
+		}
+	}
+}

+ 1 - 0
tests/misc/projects/Issue8579/compile-fail.hxml

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

+ 1 - 0
tests/misc/projects/Issue8579/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:8: characters 9-19 : A should be Int