Переглянути джерело

[typer] fail upon encountering unprocessed reification metadata (#10887)

Rudy Ges 2 роки тому
батько
коміт
bf46067443

+ 1 - 1
src/syntax/reification.ml

@@ -368,7 +368,7 @@ let reify in_macro =
 			| Meta.Dollar "i", _ ->
 				expr "EConst" [mk_enum "Constant" "CIdent" [e1] (pos e1)]
 			| Meta.Dollar "p", _ ->
-				(ECall ((efield ((efield ((efield ((EConst (Ident "haxe"),p),"macro"),p),"MacroStringTools"),p),"toFieldExpr"),p),[e]),p)
+				(ECall ((efield ((efield ((efield ((EConst (Ident "haxe"),p),"macro"),p),"MacroStringTools"),p),"toFieldExpr"),p),[e1]),p)
 			| Meta.Pos, [pexpr] ->
 				let old = !cur_pos in
 				cur_pos := Some pexpr;

+ 3 - 0
src/typing/typer.ml

@@ -1664,6 +1664,9 @@ and type_meta ?(mode=MGet) ctx m e1 with_type p =
 			| (EReturn e, p) -> type_return ~implicit:true ctx e with_type p
 			| _ -> e()
 			end
+		| (Meta.Dollar s,_,p) ->
+			display_error ctx.com (Printf.sprintf "Reification $%s is not allowed outside of `macro` expression" s) p;
+			e()
 		| _ -> e()
 	in
 	ctx.meta <- old;

+ 15 - 0
tests/misc/projects/Issue10883/Main.hx

@@ -0,0 +1,15 @@
+class Main {
+	static function main() {
+		var foo = {"a": 1, "b": 1, "c": 1};
+		test();
+		trace($i{"wtf"});
+	}
+
+	static macro function test() {
+		var options:Array<haxe.macro.Expr> = [
+			for (s in ["a", "b", "c"])
+				macro @:pos(pos) $p{["foo", s]}
+		];
+		return macro $b{options};
+	}
+}

+ 2 - 0
tests/misc/projects/Issue10883/compile-fail.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp

+ 2 - 0
tests/misc/projects/Issue10883/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:5: characters 9-11 : Reification $i is not allowed outside of `macro` expression
+Main.hx:5: characters 9-11 : Reification $i is not allowed outside of `macro` expression