فهرست منبع

[macro] fix $v in reification outside macro context (#9583)

Dmitrii Maganov 5 سال پیش
والد
کامیت
e98cc4cb90
2فایلهای تغییر یافته به همراه18 افزوده شده و 1 حذف شده
  1. 6 1
      src/syntax/reification.ml
  2. 12 0
      tests/unit/src/unit/issues/Issue9403.hx

+ 6 - 1
src/syntax/reification.ml

@@ -224,6 +224,11 @@ let reify in_macro =
 			(EUntyped (ECall ((EConst (Ident "$__mk_pos__"),p),[file;pmin;pmax]),p),p)
 		else
 			to_obj [("file",file);("min",pmin);("max",pmax)] p
+	and to_enc_pos p =
+		match !cur_pos with
+		| Some p -> p
+		| None when in_macro -> to_pos p
+		| None -> (ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"Context"),p),"makePosition"),p),[to_pos p]),p)
 	and to_expr_array a p = match a with
 		| [EMeta ((Meta.Dollar "a",[],_),e1),_] -> (match fst e1 with EArrayDecl el -> to_expr_array el p | _ -> e1)
 		| _ -> to_array to_expr a p
@@ -342,7 +347,7 @@ let reify in_macro =
 				| EParenthesis (ECheckType (e2, (CTPath{tname="String";tpackage=[]},_)),_) -> expr "EConst" [mk_enum "Constant" "CString" [e2] (pos e2)]
 				| EParenthesis (ECheckType (e2, (CTPath{tname="Int";tpackage=[]},_)),_) -> expr "EConst" [mk_enum "Constant" "CInt" [e2] (pos e2)]
 				| EParenthesis (ECheckType (e2, (CTPath{tname="Float";tpackage=[]},_)),_) -> expr "EConst" [mk_enum "Constant" "CFloat" [e2] (pos e2)]
-				| _ -> (ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"Context"),p),"makeExpr"),p),[e; to_pos (pos e)]),p)
+				| _ -> (ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"Context"),p),"makeExpr"),p),[e; to_enc_pos (pos e)]),p)
 				end
 			| Meta.Dollar "i", _ ->
 				expr "EConst" [mk_enum "Constant" "CIdent" [e1] (pos e1)]

+ 12 - 0
tests/unit/src/unit/issues/Issue9403.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+import haxe.macro.Expr;
+
+class Issue9403 extends Test {
+  #if eval
+  function test() {
+    var v = macro $v{9403};
+    t(v.expr.match(EConst(CInt('9403'))));
+  }
+  #end
+}