Browse Source

do not add `this` argument to abstract member macros methods because it will be added by member macro handler later (closes #2640)

Simon Krajewski 11 years ago
parent
commit
7423b738f2
2 changed files with 21 additions and 5 deletions
  1. 20 0
      tests/unit/issues/Issue2640.hx
  2. 1 5
      typeload.ml

+ 20 - 0
tests/unit/issues/Issue2640.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+import unit.Test;
+
+abstract A<T>(Int) {
+	public function new(i) {
+		this = i;
+	}
+	
+	macro public function test(self) {
+		var t = haxe.macro.Context.typeof(self);
+		return macro $v{haxe.macro.TypeTools.toString(t)};
+	}
+}
+
+class Issue2640 extends Test {
+	function test() {
+		var a = new A<String>(12);
+		eq(a.test(), "unit.issues.A<String>");
+	}
+}

+ 1 - 5
typeload.ml

@@ -177,11 +177,7 @@ let make_module ctx mpath file tdecls loadp =
 						{ f with cff_name = "_new"; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 						{ f with cff_name = "_new"; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 					| FFun fu when not stat ->
 					| FFun fu when not stat ->
 						if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
 						if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
-						let first = if List.mem AMacro f.cff_access
-							then CTPath ({ tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some ("ExprOf"); tparams = [TPType this_t] })
-							else this_t
-						in
-						let fu = { fu with f_args = ("this",false,Some first,None) :: fu.f_args } in
+						let fu = { fu with f_args = (if List.mem AMacro f.cff_access then fu.f_args else ("this",false,Some this_t,None) :: fu.f_args) } in
 						{ f with cff_kind = FFun fu; cff_access = AStatic :: f.cff_access; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 						{ f with cff_kind = FFun fu; cff_access = AStatic :: f.cff_access; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 					| _ ->
 					| _ ->
 						f
 						f