Răsfoiți Sursa

[matcher] follow when looking for GADT return types

closes #11446
Simon Krajewski 1 an în urmă
părinte
comite
09ccc620f4

+ 5 - 1
src/generators/genjvm.ml

@@ -2086,7 +2086,11 @@ class texpr_to_jvm
 		| TEnumParameter(e1,ef,i) ->
 			self#texpr rvalue_any e1;
 			let path,name,jsig_arg = match follow ef.ef_type with
-				| TFun(tl,TEnum(en,_)) ->
+				| TFun(tl,tr) ->
+					let en = match follow tr with
+						| TEnum(en,_) -> en
+						| _ -> die "" __LOC__
+					in
 					let n,_,t = List.nth tl i in
 					en.e_path,n,self#vtype t
 				| _ -> die "" __LOC__

+ 5 - 1
src/typing/matcher.ml

@@ -367,7 +367,11 @@ module Pattern = struct
 			| ECall(e1,el) ->
 				let e1 = type_expr ctx e1 (WithType.with_type t) in
 				begin match e1.eexpr,follow e1.etype with
-					| TField(_, FEnum(en,ef)),TFun(_,TEnum(_,tl)) ->
+					| TField(_, FEnum(en,ef)),TFun(_,tr) ->
+						let tl = match follow tr with
+							| TEnum(_,tl) -> tl
+							| _ -> fail()
+						in
 						let map = apply_params en.e_params tl in
 						let monos = Monomorph.spawn_constrained_monos map ef.ef_params in
 						let map t = map (apply_params ef.ef_params monos t) in

+ 19 - 0
tests/unit/src/unit/issues/Issue11446.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+typedef Td = E<String>;
+
+private enum E<T> {
+	C(s:String):Td;
+}
+
+private function match<T>(e:E<T>) {
+	return switch (e) {
+		case C(s): s;
+	}
+}
+
+class Issue11446 extends Test {
+	function test() {
+		eq("foo", match(C("foo")));
+	}
+}