浏览代码

do not use @:rest, instead assume trailing Array<Expr> to always be a rest argument (even if an array is passed, which is a breaking change)

Simon Krajewski 13 年之前
父节点
当前提交
a23814c216
共有 2 个文件被更改,包括 5 次插入7 次删除
  1. 3 3
      tests/unit/MyMacro.hx
  2. 2 4
      typer.ml

+ 3 - 3
tests/unit/MyMacro.hx

@@ -3,17 +3,17 @@ package unit;
 import haxe.macro.Expr;
 import haxe.macro.Expr;
 
 
 class MyRestMacro {
 class MyRestMacro {
-	@:rest @:macro static public function testRest1(e:Expr, r:Array<Expr>) {
+	@:macro static public function testRest1(e:Expr, r:Array<Expr>) {
 		var ret = [e];
 		var ret = [e];
 		for (e in r)
 		for (e in r)
 			ret.push(e);
 			ret.push(e);
 		return macro $[ret];
 		return macro $[ret];
 	}
 	}
 	
 	
-	@:rest @:macro static public function testRest2(e1:Expr, e2:Expr, r:Array<Expr>) {
+	@:macro static public function testRest2(e1:Expr, e2:Expr, r:Array<Expr>) {
 		var ret = [e1,e2];
 		var ret = [e1,e2];
 		for (e in r)
 		for (e in r)
 			ret.push(e);
 			ret.push(e);
-		return macro $[ret];		
+		return macro $[ret];
 	}
 	}
 }
 }

+ 2 - 4
typer.ml

@@ -2838,7 +2838,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 	(*
 	(*
 		if the function's last argument is of Array<Expr>, split the argument list and use [] for unify_call_params
 		if the function's last argument is of Array<Expr>, split the argument list and use [] for unify_call_params
 	*)
 	*)
-	let el,el2 = if has_meta ":rest" mfield.cf_meta then match List.rev margs with
+	let el,el2 = match List.rev margs with
 		| (_,_,TInst({cl_path=([], "Array")},[e])) :: rest when (try Type.type_eq EqStrict e expr; true with Unify_error _ -> false) ->
 		| (_,_,TInst({cl_path=([], "Array")},[e])) :: rest when (try Type.type_eq EqStrict e expr; true with Unify_error _ -> false) ->
 			let rec loop (acc1,acc2) el1 el2 = match el1,el2 with
 			let rec loop (acc1,acc2) el1 el2 = match el1,el2 with
 				| [],[] ->
 				| [],[] ->
@@ -2857,9 +2857,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 			in
 			in
 			loop ([],[]) el margs
 			loop ([],[]) el margs
 		| _ ->
 		| _ ->
-			error "Last argument of a @:rest macro must be of Array<Expr>" p
-	else
-		el,[]
+			el,[]
 	in
 	in
 	let args =
 	let args =
 		(*
 		(*