diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-02-09 19:24:00 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-02-13 10:02:06 +0100 |
commit | 2fc92eb4f0ab8f12b4ed6c2439ef9a53484b3e45 (patch) | |
tree | 057b3fd6d500acf3b84077b0730a6d534c71170d /src/compiler | |
parent | 6548dcf12d83e327df2f90048140fb95346b7e95 (diff) | |
download | scala-2fc92eb4f0ab8f12b4ed6c2439ef9a53484b3e45.tar.gz scala-2fc92eb4f0ab8f12b4ed6c2439ef9a53484b3e45.tar.bz2 scala-2fc92eb4f0ab8f12b4ed6c2439ef9a53484b3e45.zip |
Fixes https://issues.scala-lang.org/browse/SI-5453
Originally we thought that macros declared inside objects should not
provide _this to their bodies.
However, it: 1) contradicts vanilla Scala rules, according to which
both class and object methods can use this, 2) imposes unnecessary
burden on macro developers without providing any conveniences to us.
Review by @odersky.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Macros.scala | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index ed249796a8..470f3e7117 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -20,15 +20,12 @@ trait Macros { self: Analyzer => macroArgs(fn) :+ args case TypeApply(fn, args) => macroArgs(fn) :+ args - case Select(qual, name) if !isStaticMacro(tree.symbol) => + case Select(qual, name) => List(List(qual)) case _ => List(List()) } - private def isStaticMacro(mac: Symbol): Boolean = - mac.owner.isModuleClass - /** * The definition of the method implementing a macro. Example: * Say we have in a class C @@ -46,7 +43,6 @@ trait Macros { self: Analyzer => * expr * } * - * If `foo` is declared in an object, the second parameter list is () instead of (_this: _context.Tree). * If macro has no type arguments, the third parameter list is omitted (it's not empty, but omitted altogether). * * To find out the desugared representation of your particular macro, compile it with -Ymacro-debug. @@ -58,7 +54,7 @@ trait Macros { self: Analyzer => def globSelect(name: Name) = Select(Ident(nme.macroContext), name) def globTree = globSelect(tpnme.Tree) def globTypeTree = globSelect(tpnme.TypeTree) - val thisParamSec = if (isStaticMacro(mdef.symbol)) List() else List(paramDef(nme.macroThis, globTree)) + val thisParamSec = List(paramDef(newTermName(nme.macroThis), globTree)) def tparamInMacro(tdef: TypeDef) = paramDef(tdef.name.toTermName, globTypeTree) def vparamInMacro(vdef: ValDef): ValDef = paramDef(vdef.name, vdef.tpt match { case tpt @ AppliedTypeTree(hk, _) if treeInfo.isRepeatedParamType(tpt) => AppliedTypeTree(hk, List(globTree)) |