summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Macros.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-04-14 10:33:10 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-04-14 11:33:56 +0200
commit0ba3d542cc236ab2dbed3dc551920ede94787a0c (patch)
tree9e7e6e0c26a8d2f8e5b62fbf2a609349acbd8855 /src/compiler/scala/tools/nsc/typechecker/Macros.scala
parent3a2901da406f2478b5634b0636e56de9c4cd676d (diff)
downloadscala-0ba3d542cc236ab2dbed3dc551920ede94787a0c.tar.gz
scala-0ba3d542cc236ab2dbed3dc551920ede94787a0c.tar.bz2
scala-0ba3d542cc236ab2dbed3dc551920ede94787a0c.zip
restores some disabled macro tests, makes checkFeature synchronous when used for macros
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Macros.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index 988b821d1a..b7e0eaef2b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -184,8 +184,21 @@ trait Macros { self: Analyzer =>
def typedMacroBody(typer: Typer, ddef: DefDef): Tree = {
import typer.context
if (macroDebug) println("typechecking macro def %s at %s".format(ddef.symbol, ddef.pos))
+
typer.checkFeature(ddef.pos, MacrosFeature)
+ // [Eugene to Martin] todo. copy/pasted this from checkFeature, because don't know a better way
+ // this is necessary to prevent macros from typechecking/expanding when they are not enabled
+ // `checkFeature` call alone is not enough, because it merely posts validation callback to unit.toCheck
+ def hasImport = inferImplicit(EmptyTree: Tree, MacrosFeature.tpe, true, false, typer.context) != SearchFailure
+ val nestedOwners = MacrosFeature.owner.ownerChain.takeWhile(_ != languageFeatureModule.moduleClass).reverse
+ val featureName = (nestedOwners map (_.name + ".")).mkString + MacrosFeature.name
+ def hasOption = settings.language.value contains featureName
+ if (!hasImport && !hasOption) {
+ ddef.symbol setFlag IS_ERROR
+ return EmptyTree
+ }
+
implicit class AugmentedString(s: String) {
def abbreviateCoreAliases: String = { // hack!
var result = s