Browse Source

do not wrap constants used as static extension or member macros (closes #2720)

Simon Krajewski 11 years ago
parent
commit
cff0784f07
3 changed files with 23 additions and 3 deletions
  1. 9 0
      tests/unit/issues/Issue2720.hx
  2. 7 0
      tests/unit/issues/misc/Issue2720Macro.hx
  3. 7 3
      typer.ml

+ 9 - 0
tests/unit/issues/Issue2720.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+import unit.Test;
+using unit.issues.misc.Issue2720Macro;
+
+class Issue2720 extends unit.Test {
+	function test() {
+		eq("foofoo", "foo".dupe());
+	}
+}

+ 7 - 0
tests/unit/issues/misc/Issue2720Macro.hx

@@ -0,0 +1,7 @@
+package unit.issues.misc;
+
+class Issue2720Macro {
+	macro static public function dupe(s:String) {
+		return macro $v{s+s};
+	}
+}

+ 7 - 3
typer.ml

@@ -3385,9 +3385,13 @@ and build_call ctx acc el (with_type:with_type) p =
 		| _ -> None
 		| _ -> None
 	in
 	in
 	let push_this e =
 	let push_this e =
-		ctx.this_stack <- e :: ctx.this_stack;
-		let er = EMeta((Meta.This,[],e.epos), (EConst(Ident "this"),e.epos)),e.epos in
-		er,fun () -> ctx.this_stack <- List.tl ctx.this_stack
+		match e.eexpr with
+			| TConst (TInt _ | TFloat _ | TString _ | TBool _) ->
+				(Interp.make_ast e),fun () -> ()
+			| _ ->
+				ctx.this_stack <- e :: ctx.this_stack;
+				let er = EMeta((Meta.This,[],e.epos), (EConst(Ident "this"),e.epos)),e.epos in
+				er,fun () -> ctx.this_stack <- List.tl ctx.this_stack
 	in
 	in
 	match acc with
 	match acc with
 	| AKInline (ethis,f,fmode,t) when Meta.has Meta.Generic f.cf_meta ->
 	| AKInline (ethis,f,fmode,t) when Meta.has Meta.Generic f.cf_meta ->