Browse Source

follow harder (#9828)

Aleksandr Kuzmenko 5 years ago
parent
commit
185bdb4a90
2 changed files with 21 additions and 18 deletions
  1. 11 7
      src/macro/macroApi.ml
  2. 10 11
      tests/unit/src/unit/issues/Issue9828.hx

+ 11 - 7
src/macro/macroApi.ml

@@ -1334,13 +1334,17 @@ let decode_cfield v =
 	cf
 	cf
 
 
 let decode_efield v =
 let decode_efield v =
-	let name = decode_string (field v "name")
-	and t = decode_type (field v "type") in
-	match follow t with
-	| TEnum (enm,_) | TFun (_,TEnum (enm,_)) ->
-		(try PMap.find name enm.e_constrs
-		with Not_found -> raise Invalid_expr)
-	| _ ->
+	let rec get_enum t =
+		match follow t with
+		| TEnum (enm,_) -> enm
+		| TFun (_,t) -> get_enum t
+		| _ -> raise Not_found
+	in
+	let name = decode_string (field v "name") in
+	try
+		let enm = get_enum (decode_type (field v "type")) in
+		PMap.find name enm.e_constrs
+	with Not_found ->
 		raise Invalid_expr
 		raise Invalid_expr
 
 
 let decode_field_access v =
 let decode_field_access v =

+ 10 - 11
tests/unit/src/unit/issues/Issue9828.hx

@@ -1,29 +1,28 @@
 package unit.issues;
 package unit.issues;
 
 
 import haxe.macro.Context.*;
 import haxe.macro.Context.*;
-import haxe.ds.Option;
 
 
 #if macro
 #if macro
 class Issue9828 {
 class Issue9828 {
-	static macro function foo() {
-		var t = typeExpr(macro {
-			var y:Option<String> = x;
-			switch y {
-				case Some(v): v;
-				case None: '';
-			}
-		});
+	static macro function foo(e) {
+		var t = typeExpr(e);
 		return storeTypedExpr(t);
 		return storeTypedExpr(t);
 	}
 	}
 }
 }
 #else
 #else
 class Issue9828 extends unit.Test {
 class Issue9828 extends unit.Test {
-	var x = Some('hello');
+	var x = BadCtor(123);
 
 
 	function test() {
 	function test() {
-		eq('hello', foo());
+		t(Type.enumEq(BadCtor(123), foo(BadCtor(123))));
 	}
 	}
 
 
 	static macro function foo(e:haxe.macro.Expr):haxe.macro.Expr;
 	static macro function foo(e:haxe.macro.Expr):haxe.macro.Expr;
 }
 }
+
+private typedef BadTypedef = BadGadt<Int>;
+
+private enum BadGadt<T> {
+	BadCtor(v:Int):BadTypedef;
+}
 #end
 #end