Selaa lähdekoodia

[macro] fixed `decode_efield` for enum ctors with arguments (closes #9828)

Aleksandr Kuzmenko 5 vuotta sitten
vanhempi
commit
c72b4beeb1
2 muutettua tiedostoa jossa 30 lisäystä ja 1 poistoa
  1. 1 1
      src/macro/macroApi.ml
  2. 29 0
      tests/unit/src/unit/issues/Issue9828.hx

+ 1 - 1
src/macro/macroApi.ml

@@ -1337,7 +1337,7 @@ let decode_efield v =
 	let name = decode_string (field v "name")
 	and t = decode_type (field v "type") in
 	match t with
-	| TEnum (enm,_) ->
+	| TEnum (enm,_) | TFun (_,TEnum (enm,_)) ->
 		(try PMap.find name enm.e_constrs
 		with Not_found -> raise Invalid_expr)
 	| _ ->

+ 29 - 0
tests/unit/src/unit/issues/Issue9828.hx

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