Ver código fonte

[macro] hack around generate pos problem

closes #8261
Simon Krajewski 6 anos atrás
pai
commit
3bb1ff98a0
2 arquivos alterados com 25 adições e 3 exclusões
  1. 6 3
      src/macro/eval/evalMain.ml
  2. 19 0
      tests/unit/src/unit/issues/Issue8261.hx

+ 6 - 3
src/macro/eval/evalMain.ml

@@ -415,9 +415,13 @@ let rec value_to_expr v p =
 	| VFloat f -> haxe_float f p
 	| VString s -> (EConst (String s.sstring),p)
 	| VArray va -> (EArrayDecl (List.map (fun v -> value_to_expr v p) (EvalArray.to_list va)),p)
-	| VObject o -> (EObjectDecl (List.map (fun (k,v) ->
+	| VObject o -> (EObjectDecl (ExtList.List.filter_map (fun (k,v) ->
 			let n = rev_hash k in
-			((n,p,(if Lexer.is_valid_identifier n then NoQuotes else DoubleQuotes)),(value_to_expr v p))
+			(* Workaround for #8261: Ignore generated pos fields *)
+			begin match v with
+			| VInstance {ikind = IPos _} when n = "pos" -> None
+			| _ -> Some ((n,p,(if Lexer.is_valid_identifier n then NoQuotes else DoubleQuotes)),(value_to_expr v p))
+			end
 		) (object_fields o)),p)
 	| VEnumValue e ->
 		let epath =
@@ -436,7 +440,6 @@ let rec value_to_expr v p =
 				let args = List.map (fun v -> value_to_expr v p) (Array.to_list e.eargs) in
 				(ECall (epath, args), p)
 		end
-
 	| _ -> exc_string ("Cannot convert " ^ (value_string v) ^ " to expr")
 
 let encode_obj = encode_obj_s

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

@@ -0,0 +1,19 @@
+package unit.issues;
+
+class Issue8261 extends unit.Test {
+	function test() {
+		#if !macro
+		var ct = getComplexType();
+		var name = switch (ct) {
+			case TPath(path): path.sub;
+			case _: null;
+		}
+		eq("Int", name);
+		#end
+	}
+
+    macro static function getComplexType() {
+        var ct = haxe.macro.Context.toComplexType(haxe.macro.Context.getType("Int"));
+        return macro $v{ct};
+    }
+}