Bladeren bron

warn about @:macro becoming macro with -D haxe3 + deprecated class-macro

Nicolas Cannasse 12 jaren geleden
bovenliggende
commit
976c190543

+ 1 - 1
std/haxe/macro/Compiler.hx

@@ -283,7 +283,7 @@ class Compiler {
 	/**
 		Embed an on-disk javascript file (can be called into an __init__ method)
 	**/
-	@:macro public static function includeFile( fileName : Expr ) {
+	public static macro function includeFile( fileName : Expr ) {
 		var str = switch( fileName.expr ) {
 		case EConst(c):
 			switch( c ) {

+ 4 - 4
std/haxe/web/Dispatch.hx

@@ -78,13 +78,13 @@ class Dispatch {
 		this.params = params;
 	}
 
-	@:macro public function dispatch( ethis : Expr, obj : ExprOf<{}> ) : ExprOf<Void> {
+	public macro function dispatch( ethis : Expr, obj : ExprOf<{}> ) : ExprOf<Void> {
 		var p = Context.currentPos();
 		var cfg = makeConfig(obj);
 		return { expr : ECall({ expr : EField(ethis, "runtimeDispatch"), pos : p }, [cfg]), pos : p };
 	}
 
-	@:macro public function getParams( ethis : Expr ) : Expr {
+	public macro function getParams( ethis : Expr ) : Expr {
 		var p = Context.currentPos();
 		if( PARAMS == null ) {
 			PARAMS = new Array();
@@ -424,11 +424,11 @@ class Dispatch {
 
 	#end
 
-	@:macro public static function make( obj : ExprOf<{}> ) : ExprOf<DispatchConfig> {
+	public static macro function make( obj : ExprOf<{}> ) : ExprOf<DispatchConfig> {
 		return makeConfig(obj);
 	}
 
-	@:macro public static function run( url : ExprOf<String>, params : ExprOf<Hash<String>>, obj : ExprOf<{}> ) : ExprOf<Void> {
+	public static macro function run( url : ExprOf<String>, params : ExprOf<Hash<String>>, obj : ExprOf<{}> ) : ExprOf<Void> {
 		var p = Context.currentPos();
 		var cfg = makeConfig(obj);
 		return { expr : ECall({ expr : EField({ expr : ENew({ name : "Dispatch", pack : ["haxe","web"], params : [], sub : null },[url,params]), pos : p },"runtimeDispatch"), pos : p },[cfg]), pos : p };

+ 5 - 5
std/sys/db/Manager.hx

@@ -81,23 +81,23 @@ class Manager<T : Object> {
 		return unsafeObjects("SELECT * FROM " + table_name,lock);
 	}
 
-	@:macro public function get(ethis,id,?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<T> #end {
+	public macro function get(ethis,id,?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<T> #end {
 		return SpodMacros.macroGet(ethis,id,lock);
 	}
 
-	@:macro public function select(ethis, cond, ?options, ?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<T> #end {
+	public macro function select(ethis, cond, ?options, ?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<T> #end {
 		return SpodMacros.macroSearch(ethis, cond, options, lock, true);
 	}
 
-	@:macro public function search(ethis, cond, ?options, ?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<List<T>> #end {
+	public macro function search(ethis, cond, ?options, ?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<List<T>> #end {
 		return SpodMacros.macroSearch(ethis, cond, options, lock);
 	}
 
-	@:macro public function count(ethis, cond) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<Int> #end {
+	public macro function count(ethis, cond) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<Int> #end {
 		return SpodMacros.macroCount(ethis, cond);
 	}
 
-	@:macro public function delete(ethis, cond, ?options) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<Void> #end {
+	public macro function delete(ethis, cond, ?options) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<Void> #end {
 		return SpodMacros.macroDelete(ethis, cond, options);
 	}
 

+ 2 - 2
tests/unit/MyMacro.hx

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

+ 1 - 1
tests/unit/TestMatch.hx

@@ -18,7 +18,7 @@ enum X<A> {
 }
 
 class TestMatch extends Test {
-	@:macro static function getErrorMessage(e:Expr) {
+	static macro function getErrorMessage(e:Expr) {
 		var result = try {
 			haxe.macro.Context.typeof(e);
 			"no error";

+ 1 - 1
tests/unit/TestMeta.hx

@@ -68,7 +68,7 @@ package unit;
 		eq(getMeta(@foo("1") "2").args.length, 1);
 	}
 
-	@:macro static function getMeta(e) {
+	static macro function getMeta(e) {
 		switch(e.expr) {
 			case EMeta(m, _):
 				return macro { name: $v{m.name}, args: $a{m.params} };

+ 3 - 3
tests/unit/TestType.hx

@@ -12,13 +12,13 @@ class TestType extends Test {
 		#end
 	}
 
-	@:macro static public function typedAs(actual:haxe.macro.Expr, expected:haxe.macro.Expr) {
+	static public macro function typedAs(actual:haxe.macro.Expr, expected:haxe.macro.Expr) {
 		var tExpected = haxe.macro.Context.typeof(expected);
 		var tActual = haxe.macro.Context.typeof(actual);
 		return haxe.macro.Context.parse("{Test.count++; eq('" +Std.string(tActual) + "', '" +Std.string(tExpected) + "');}", haxe.macro.Context.currentPos());
 	}
 
-	@:macro static public function typeError(e:haxe.macro.Expr) {
+	static public macro function typeError(e:haxe.macro.Expr) {
 		var result = try {
 			haxe.macro.Context.typeof(e);
 			"false";
@@ -26,7 +26,7 @@ class TestType extends Test {
 		return { pos: haxe.macro.Context.currentPos(), expr: haxe.macro.Expr.ExprDef.EConst(haxe.macro.Expr.Constant.CIdent(result)) };
 	}
 
-	@:macro static public function complete(e:String) : haxe.macro.Expr.ExprOf<String> {
+	static public macro function complete(e:String) : haxe.macro.Expr.ExprOf<String> {
 		var str = new String(untyped haxe.macro.Context.load("display", 1)(e.__s));
 		return { expr : EConst(CString(str)), pos : haxe.macro.Context.currentPos() };
 	}

+ 1 - 1
tests/unit/UnitBuilder.hx

@@ -29,7 +29,7 @@ using StringTools;
 
 class UnitBuilder {
 	
-	@:macro static public function build(basePath:String):Array<Field> {
+	static public macro function build(basePath:String):Array<Field> {
 		var ret = Context.getBuildFields();
 		var numFiles = 0;
 			

+ 4 - 1
typeload.ml

@@ -1013,6 +1013,7 @@ let init_class ctx c p context_init herits fields =
 	let fields = !fields in
 	let core_api = has_meta ":coreApi" c.cl_meta in
 	let is_class_macro = has_meta ":macro" c.cl_meta in
+	if is_class_macro && Common.defined ctx.com Define.Haxe3 then display_error ctx "Macro-class is no longer allowed in haxe3" p;
 	let fields, herits = if is_class_macro && not ctx.in_macro then begin
 		c.cl_extern <- true;
 		List.filter (fun f -> List.mem AStatic f.cff_access) fields, []
@@ -1149,7 +1150,9 @@ let init_class ctx c p context_init herits fields =
 		let extern = has_meta ":extern" f.cff_meta || c.cl_extern in
 		let inline = List.mem AInline f.cff_access && (match f.cff_kind with FFun _ -> not ctx.com.display && (ctx.g.doinline || extern) | _ -> true) in
 		let override = List.mem AOverride f.cff_access in
-		let is_macro = List.mem AMacro f.cff_access || has_meta ":macro" f.cff_meta in
+		let is_macro = has_meta ":macro" f.cff_meta in
+		if is_macro && Common.defined ctx.com Define.Haxe3 then ctx.com.warning "@:macro should now be 'macro' accessor'" p;
+		let is_macro = is_macro || List.mem AMacro f.cff_access in
 		List.iter (fun acc ->
 			match (acc, f.cff_kind) with
 			| APublic, _ | APrivate, _ | AStatic, _ -> ()