From 0ba3d542cc236ab2dbed3dc551920ede94787a0c Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sat, 14 Apr 2012 10:33:10 +0200 Subject: restores some disabled macro tests, makes checkFeature synchronous when used for macros --- src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 2 +- src/compiler/scala/tools/nsc/typechecker/Macros.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index b4e0ad6edf..4fb9362ccc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -166,7 +166,7 @@ trait Implicits { } def isCyclicOrErroneous = - try containsError(tpe) + try sym.hasFlag(LOCKED) || containsError(tpe) catch { case _: CyclicReference => true } var useCountArg: Int = 0 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 -- cgit v1.2.3