summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/reflect/macros/compiler/Errors.scala2
-rw-r--r--src/compiler/scala/reflect/macros/compiler/Resolvers.scala35
-rw-r--r--src/compiler/scala/reflect/macros/compiler/Validators.scala6
-rw-r--r--src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala19
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala44
-rw-r--r--src/reflect/scala/reflect/macros/blackbox/Macro.scala40
-rw-r--r--src/reflect/scala/reflect/macros/whitebox/Macro.scala40
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala2
-rw-r--r--test/files/neg/macro-bundle-abstract.check6
-rw-r--r--test/files/neg/macro-bundle-abstract.scala4
-rw-r--r--test/files/neg/macro-bundle-class.check4
-rw-r--r--test/files/neg/macro-bundle-class.scala10
-rw-r--r--test/files/neg/macro-bundle-mixbox.check4
-rw-r--r--test/files/neg/macro-bundle-mixbox.scala11
-rw-r--r--test/files/neg/macro-bundle-noncontext.check4
-rw-r--r--test/files/neg/macro-bundle-noncontext.scala (renamed from test/files/neg/macro-bundle-nonmacro.scala)2
-rw-r--r--test/files/neg/macro-bundle-nonmacro.check4
-rw-r--r--test/files/neg/macro-bundle-object.scala4
-rw-r--r--test/files/neg/macro-bundle-polymorphic.check10
-rw-r--r--test/files/neg/macro-bundle-polymorphic.scala12
-rw-r--r--test/files/neg/macro-bundle-trait.check2
-rw-r--r--test/files/neg/macro-bundle-trait.scala4
-rw-r--r--test/files/neg/macro-quasiquotes/Macros_1.scala4
-rw-r--r--test/files/run/macro-bundle-repl.check12
-rw-r--r--test/files/run/macro-bundle-repl.scala6
-rw-r--r--test/files/run/macro-bundle-static/Impls_Macros_1.scala6
-rw-r--r--test/files/run/macro-bundle-static/Test_2.scala4
-rw-r--r--test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala6
-rw-r--r--test/files/run/macro-bundle-toplevel/Test_2.scala4
-rw-r--r--test/files/run/macro-bundle-whitebox.check6
-rw-r--r--test/files/run/macro-bundle-whitebox/Impls_Macros_1.scala26
-rw-r--r--test/files/run/macro-bundle-whitebox/Test_2.scala8
-rw-r--r--test/files/run/macro-quasiquotes/Macros_1.scala4
34 files changed, 108 insertions, 251 deletions
diff --git a/src/compiler/scala/reflect/macros/compiler/Errors.scala b/src/compiler/scala/reflect/macros/compiler/Errors.scala
index a408a6ec62..6b6d4248aa 100644
--- a/src/compiler/scala/reflect/macros/compiler/Errors.scala
+++ b/src/compiler/scala/reflect/macros/compiler/Errors.scala
@@ -51,7 +51,7 @@ trait Errors extends Traces {
def MacroBundleNonStaticError() = bundleRefError("macro bundles must be static")
- def MacroBundleWrongShapeError() = bundleRefError("macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member")
+ def MacroBundleWrongShapeError() = bundleRefError("macro bundles must be concrete classes having a single `val c: Context` parameter")
// compatibility errors
diff --git a/src/compiler/scala/reflect/macros/compiler/Resolvers.scala b/src/compiler/scala/reflect/macros/compiler/Resolvers.scala
index 05daf852ef..d35f1c32a9 100644
--- a/src/compiler/scala/reflect/macros/compiler/Resolvers.scala
+++ b/src/compiler/scala/reflect/macros/compiler/Resolvers.scala
@@ -40,36 +40,11 @@ trait Resolvers {
}
val untypedImplRef = typer.silent(_.typedTypeConstructor(maybeBundleRef)) match {
- case SilentResultValue(result) if mightBeMacroBundleType(result.tpe) =>
- val bundleProto = result.tpe.typeSymbol
- val bundlePkg = bundleProto.enclosingPackageClass
- if (!isMacroBundleProtoType(bundleProto.tpe)) MacroBundleWrongShapeError()
- if (!bundleProto.owner.isStaticOwner) MacroBundleNonStaticError()
-
- // synthesize the bundle, i.e. given a static `trait Foo extends *box.Macro { def expand = ... } `
- // create a top-level definition `class Foo$Bundle(val c: *box.Context) extends Foo` in a package next to `Foo`
- val bundlePid = gen.mkUnattributedRef(bundlePkg)
- val bundlePrefix =
- if (bundlePkg == EmptyPackageClass) bundleProto.fullName('$')
- else bundleProto.fullName('$').substring(bundlePkg.fullName('$').length + 1)
- val bundleName = TypeName(bundlePrefix + tpnme.MACRO_BUNDLE_SUFFIX)
- val existingBundle = bundleProto.enclosingPackageClass.info.decl(bundleName)
- if (!currentRun.compiles(existingBundle)) {
- val contextType = if (isBlackboxMacroBundleType(bundleProto.tpe)) BlackboxContextClass.tpe else WhiteboxContextClass.tpe
- def mkContextValDef(flags: Long) = ValDef(Modifiers(flags), nme.c, TypeTree(contextType), EmptyTree)
- val contextField = mkContextValDef(PARAMACCESSOR)
- val contextParam = mkContextValDef(PARAM | PARAMACCESSOR)
- val bundleCtor = DefDef(Modifiers(), nme.CONSTRUCTOR, Nil, List(List(contextParam)), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(()))))
- val bundleParent = gen.mkAppliedTypeTree(Ident(bundleProto), bundleProto.typeParams.map(sym => Ident(sym.name)))
- val bundleTemplate = Template(List(bundleParent), noSelfType, List(contextField, bundleCtor))
- val bundle = atPos(bundleProto.pos)(ClassDef(NoMods, bundleName, bundleProto.typeParams.map(TypeDef(_)), bundleTemplate))
- currentRun.compileLate(bundleName + ".scala", PackageDef(bundlePid, List(bundle)))
- }
-
- // synthesize the macro impl reference, which is going to look like:
- // `new FooBundle(???).macroName` plus the optional type arguments
- val bundleInstance = New(Select(bundlePid, bundleName), List(List(Ident(Predef_???))))
- atPos(macroDdef.rhs.pos)(gen.mkTypeApply(Select(bundleInstance, methName), targs))
+ case SilentResultValue(result) if looksLikeMacroBundleType(result.tpe) =>
+ val bundle = result.tpe.typeSymbol
+ if (!isMacroBundleType(bundle.tpe)) MacroBundleWrongShapeError()
+ if (!bundle.owner.isStaticOwner) MacroBundleNonStaticError()
+ atPos(macroDdef.rhs.pos)(gen.mkTypeApply(Select(New(bundle, Ident(Predef_???)), methName), targs))
case _ =>
macroDdef.rhs
}
diff --git a/src/compiler/scala/reflect/macros/compiler/Validators.scala b/src/compiler/scala/reflect/macros/compiler/Validators.scala
index 95cb0f7466..02c1f7c431 100644
--- a/src/compiler/scala/reflect/macros/compiler/Validators.scala
+++ b/src/compiler/scala/reflect/macros/compiler/Validators.scala
@@ -26,9 +26,9 @@ trait Validators {
if (macroImpl.isOverloaded) MacroImplOverloadedError()
val implicitParams = aparamss.flatten filter (_.isImplicit)
if (implicitParams.nonEmpty) MacroImplNonTagImplicitParameters(implicitParams)
- val declaredInStaticObject = isImplMethod && (macroImplOwner.isStaticOwner || macroImplOwner.moduleClass.isStaticOwner)
- val declaredInTopLevelClass = isImplBundle && macroImplOwner.owner.isPackageClass
- if (!declaredInStaticObject && !declaredInTopLevelClass) MacroImplReferenceWrongShapeError()
+ val effectiveOwner = if (isImplMethod) macroImplOwner else macroImplOwner.owner
+ val declaredInStaticObject = effectiveOwner.isStaticOwner || effectiveOwner.moduleClass.isStaticOwner
+ if (!declaredInStaticObject) MacroImplReferenceWrongShapeError()
}
private def checkMacroDefMacroImplCorrespondence() = {
diff --git a/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala b/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala
index 450cb4d9ea..8ad38ff5f0 100644
--- a/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala
+++ b/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala
@@ -2,7 +2,7 @@ package scala.reflect.macros
package runtime
import scala.reflect.runtime.ReflectionUtils
-import scala.reflect.macros.{Context => ApiContext}
+import scala.reflect.macros.blackbox.{Context => ApiContext}
trait JavaReflectionRuntimes {
self: scala.tools.nsc.typechecker.Analyzer =>
@@ -19,7 +19,7 @@ trait JavaReflectionRuntimes {
macroLogVerbose(s"successfully loaded macro impl as ($implClass, $implMeth)")
args => {
val implObj =
- if (isBundle) implClass.getConstructor(classOf[ApiContext]).newInstance(args.c)
+ if (isBundle) implClass.getConstructors().head.newInstance(args.c)
else ReflectionUtils.staticSingletonInstance(implClass)
val implArgs = if (isBundle) args.others else args.c +: args.others
implMeth.invoke(implObj, implArgs.asInstanceOf[Seq[AnyRef]]: _*)
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 5f079a428b..5492e563dd 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -1710,25 +1710,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
}
- /** Create and compile a synthetic compilation unit from the provided tree.
- *
- * This needs to create a virtual file underlying the compilation unit in order to appease SBT.
- * However this file cannot have a randomly generated name, because then SBT 0.13 goes into a vicious loop
- * as described on the mailing list: https://groups.google.com/forum/#!msg/scala-user/r1SgSoVfs0U/Wv4av0LOKukJ
- * Therefore I have introduced an additional parameter that makes everyone specify meaningful file names.
- */
- def compileLate(virtualFileName: String, code: PackageDef) {
- // compatibility with SBT
- // on the one hand, we need to specify some jfile here, otherwise sbt crashes with an NPE (SI-6870)
- // on the other hand, we can't specify the obvious enclosingUnit, because then sbt somehow fails to run tests using type macros
- val fakeJfile = new java.io.File(virtualFileName)
- val virtualFile = new VirtualFile(virtualFileName) { override def file = fakeJfile }
- val sourceFile = new BatchSourceFile(virtualFile, code.toString)
- val unit = new CompilationUnit(sourceFile)
- unit.body = code
- compileLate(unit)
- }
-
/** Reset package class to state at typer (not sure what this
* is needed for?)
*/
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 133442bdb5..03826a3011 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -482,10 +482,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val TypeCreatorClass = getClassIfDefined("scala.reflect.api.TypeCreator") // defined in scala-reflect.jar, so we need to be careful
lazy val TreeCreatorClass = getClassIfDefined("scala.reflect.api.TreeCreator") // defined in scala-reflect.jar, so we need to be careful
- lazy val BlackboxMacroClass = getClassIfDefined("scala.reflect.macros.blackbox.Macro") // defined in scala-reflect.jar, so we need to be careful
- def BlackboxMacroContextValue = BlackboxMacroClass.map(sym => getMemberValue(sym, nme.c))
- lazy val WhiteboxMacroClass = getClassIfDefined("scala.reflect.macros.whitebox.Macro") // defined in scala-reflect.jar, so we need to be careful
- def WhiteboxMacroContextValue = WhiteboxMacroClass.map(sym => getMemberValue(sym, nme.c))
lazy val BlackboxContextClass = getClassIfDefined("scala.reflect.macros.blackbox.Context") // defined in scala-reflect.jar, so we need to be careful
lazy val WhiteboxContextClass = getClassIfDefined("scala.reflect.macros.whitebox.Context") // defined in scala-reflect.jar, so we need to be careful
def MacroContextPrefix = BlackboxContextClass.map(sym => getMemberMethod(sym, nme.prefix))
@@ -603,32 +599,30 @@ trait Definitions extends api.StandardDefinitions {
def isWhiteboxContextType(tp: Type) =
isMacroContextType(tp) && (tp <:< WhiteboxContextClass.tpe)
- def mightBeMacroBundleType(tp: Type) =
- tp.baseClasses.contains(WhiteboxMacroClass) ||
- tp.baseClasses.contains(BlackboxMacroClass)
-
- def isMacroBundleType(tp: Type) = tp.baseClasses match {
- case _ :: proto :: _ if isMacroBundleProtoType(proto.tpe) => true
- case _ => false
+ private def macroBundleParamInfo(tp: Type) = {
+ val ctor = tp.erasure.typeSymbol.primaryConstructor
+ ctor.paramss match {
+ case List(List(c)) =>
+ val sym = c.info.typeSymbol
+ val isContextCompatible = sym.isNonBottomSubClass(BlackboxContextClass) || sym.isNonBottomSubClass(WhiteboxContextClass)
+ if (isContextCompatible) c.info else NoType
+ case _ =>
+ NoType
+ }
}
- def isBlackboxMacroBundleType(tp: Type) =
- isMacroBundleType(tp) && (tp <:< BlackboxMacroClass.tpe) && !(tp <:< WhiteboxMacroClass.tpe)
+ def looksLikeMacroBundleType(tp: Type) =
+ macroBundleParamInfo(tp) != NoType
- def isMacroBundleProtoType(tp: Type) = {
- val sym = tp.typeSymbol
- val isNonTrivial = tp != ErrorType && tp != NothingTpe && tp != NullTpe
- def subclasses(sym: Symbol) = sym != NoSymbol && tp.baseClasses.contains(sym)
- val isMacroCompatible = subclasses(BlackboxMacroClass) ^ subclasses(WhiteboxMacroClass)
- val isBundlePrototype = sym != BlackboxMacroClass && sym != WhiteboxMacroClass && sym.isTrait && {
- val c = sym.info.member(nme.c)
- def overrides(sym: Symbol) = c.overrideChain.contains(sym)
- val cIsOk = (overrides(BlackboxMacroContextValue) || overrides(WhiteboxMacroContextValue)) && c.isDeferred
- cIsOk && sym.isMonomorphicType
- }
- isNonTrivial && isMacroCompatible && isBundlePrototype
+ def isMacroBundleType(tp: Type) = {
+ val isContextCompatible = macroBundleParamInfo(tp) != NoType
+ val nonAbstract = !tp.erasure.typeSymbol.isAbstractClass
+ isContextCompatible && nonAbstract
}
+ def isBlackboxMacroBundleType(tp: Type) =
+ isMacroBundleType(tp) && (macroBundleParamInfo(tp) <:< BlackboxContextClass.tpe)
+
def isIterableType(tp: Type) = tp <:< classExistentialType(IterableClass)
// These "direct" calls perform no dealiasing. They are most needed when
diff --git a/src/reflect/scala/reflect/macros/blackbox/Macro.scala b/src/reflect/scala/reflect/macros/blackbox/Macro.scala
deleted file mode 100644
index e51aca6896..0000000000
--- a/src/reflect/scala/reflect/macros/blackbox/Macro.scala
+++ /dev/null
@@ -1,40 +0,0 @@
-package scala
-package reflect
-package macros
-package blackbox
-
-/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
- *
- * Traditionally macro implementations are defined as methods,
- * but this trait provides an alternative way of encoding macro impls as
- * bundles, traits which extend `scala.reflect.macros.blackbox.Macro` or`scala.reflect.macros.whitebox.Macro` .
- *
- * Instead of:
- *
- * import scala.reflect.macros.blackbox._
- * def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[Int]) = ...
- *
- * One can write:
- *
- * import scala.reflect.macros.blackbox._
- * trait Impl extends Macro {
- * def apply[T: c.WeakTypeTag](x: c.Expr[Int]) = ...
- * }
- *
- * Without changing anything else at all.
- *
- * This language feature is useful in itself in cases when macro implementations
- * are complex and need to be modularized. State of the art technique of addressing this need is quite heavyweight:
- * http://docs.scala-lang.org/overviews/macros/overview.html#writing_bigger_macros.
- *
- * @see `scala.reflect.macros.whitebox.Macro`
- */
-trait Macro {
- /** The context to be used by the macro implementation.
- *
- * Vanilla macro implementations have to carry it in their signatures, however when a macro is a full-fledged module,
- * it can define the context next to the implementation, makes implementation signature more lightweight.
- */
- val c: Context
-}
diff --git a/src/reflect/scala/reflect/macros/whitebox/Macro.scala b/src/reflect/scala/reflect/macros/whitebox/Macro.scala
deleted file mode 100644
index af8539268e..0000000000
--- a/src/reflect/scala/reflect/macros/whitebox/Macro.scala
+++ /dev/null
@@ -1,40 +0,0 @@
-package scala
-package reflect
-package macros
-package whitebox
-
-/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
- *
- * Traditionally macro implementations are defined as methods,
- * but this trait provides an alternative way of encoding macro impls as
- * bundles, traits which extend `scala.reflect.macros.blackbox.Macro` or`scala.reflect.macros.whitebox.Macro` .
- *
- * Instead of:
- *
- * import scala.reflect.macros.whitebox._
- * def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[Int]) = ...
- *
- * One can write:
- *
- * import scala.reflect.macros.whitebox._
- * trait Impl extends Macro {
- * def apply[T: c.WeakTypeTag](x: c.Expr[Int]) = ...
- * }
- *
- * Without changing anything else at all.
- *
- * This language feature is useful in itself in cases when macro implementations
- * are complex and need to be modularized. State of the art technique of addressing this need is quite heavyweight:
- * http://docs.scala-lang.org/overviews/macros/overview.html#writing_bigger_macros.
- *
- * @see `scala.reflect.macros.blackbox.Macro`
- */
-trait Macro {
- /** The context to be used by the macro implementation.
- *
- * Vanilla macro implementations have to carry it in their signatures, however when a macro is a full-fledged module,
- * it can define the context next to the implementation, makes implementation signature more lightweight.
- */
- val c: Context
-}
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index c87995275f..7ba8a0a295 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -319,8 +319,6 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.MirrorClass
definitions.TypeCreatorClass
definitions.TreeCreatorClass
- definitions.BlackboxMacroClass
- definitions.WhiteboxMacroClass
definitions.BlackboxContextClass
definitions.WhiteboxContextClass
definitions.MacroImplAnnotation
diff --git a/test/files/neg/macro-bundle-abstract.check b/test/files/neg/macro-bundle-abstract.check
index 8766e2a436..010d0768c9 100644
--- a/test/files/neg/macro-bundle-abstract.check
+++ b/test/files/neg/macro-bundle-abstract.check
@@ -1,4 +1,4 @@
-macro-bundle-abstract.scala:4: error: class Bundle$Bundle needs to be abstract, since method deferred in trait Bundle of type => Int is not defined
-trait Bundle extends Macro {
- ^
+macro-bundle-abstract.scala:10: error: macro bundles must be concrete classes having a single `val c: Context` parameter
+ def foo = macro Bundle.impl
+ ^
one error found
diff --git a/test/files/neg/macro-bundle-abstract.scala b/test/files/neg/macro-bundle-abstract.scala
index 4ed2f4f7e5..0afeaafc01 100644
--- a/test/files/neg/macro-bundle-abstract.scala
+++ b/test/files/neg/macro-bundle-abstract.scala
@@ -1,7 +1,7 @@
import scala.language.experimental.macros
-import scala.reflect.macros.blackbox.Macro
+import scala.reflect.macros.blackbox.Context
-trait Bundle extends Macro {
+abstract class Bundle(c: Context) {
def deferred: Int
def impl = ???
}
diff --git a/test/files/neg/macro-bundle-class.check b/test/files/neg/macro-bundle-class.check
deleted file mode 100644
index 95ba45b169..0000000000
--- a/test/files/neg/macro-bundle-class.check
+++ /dev/null
@@ -1,4 +0,0 @@
-macro-bundle-class.scala:9: error: macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member
- def foo = macro Bundle.impl
- ^
-one error found
diff --git a/test/files/neg/macro-bundle-class.scala b/test/files/neg/macro-bundle-class.scala
deleted file mode 100644
index 40a7ae0625..0000000000
--- a/test/files/neg/macro-bundle-class.scala
+++ /dev/null
@@ -1,10 +0,0 @@
-import scala.language.experimental.macros
-import scala.reflect.macros.blackbox._
-
-class Bundle(val c: Context) extends Macro {
- def impl = ???
-}
-
-object Macros {
- def foo = macro Bundle.impl
-} \ No newline at end of file
diff --git a/test/files/neg/macro-bundle-mixbox.check b/test/files/neg/macro-bundle-mixbox.check
deleted file mode 100644
index 38aad273ea..0000000000
--- a/test/files/neg/macro-bundle-mixbox.check
+++ /dev/null
@@ -1,4 +0,0 @@
-macro-bundle-mixbox.scala:10: error: macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member
- def foo = macro Bundle.impl
- ^
-one error found
diff --git a/test/files/neg/macro-bundle-mixbox.scala b/test/files/neg/macro-bundle-mixbox.scala
deleted file mode 100644
index 17120aaf07..0000000000
--- a/test/files/neg/macro-bundle-mixbox.scala
+++ /dev/null
@@ -1,11 +0,0 @@
-import scala.language.experimental.macros
-import scala.reflect.macros.blackbox.{Macro => BlackboxMacro}
-import scala.reflect.macros.whitebox.{Macro => WhiteboxMacro}
-
-trait Bundle extends BlackboxMacro with WhiteboxMacro {
- def impl = ???
-}
-
-object Macros {
- def foo = macro Bundle.impl
-} \ No newline at end of file
diff --git a/test/files/neg/macro-bundle-noncontext.check b/test/files/neg/macro-bundle-noncontext.check
new file mode 100644
index 0000000000..bb5d0851f5
--- /dev/null
+++ b/test/files/neg/macro-bundle-noncontext.check
@@ -0,0 +1,4 @@
+macro-bundle-noncontext.scala:8: error: not found: value Bundle
+ def foo = Bundle.impl
+ ^
+one error found
diff --git a/test/files/neg/macro-bundle-nonmacro.scala b/test/files/neg/macro-bundle-noncontext.scala
index c7d99f4582..c228827e70 100644
--- a/test/files/neg/macro-bundle-nonmacro.scala
+++ b/test/files/neg/macro-bundle-noncontext.scala
@@ -1,6 +1,6 @@
import scala.language.experimental.macros
-trait Bundle {
+class Bundle {
def impl = ???
}
diff --git a/test/files/neg/macro-bundle-nonmacro.check b/test/files/neg/macro-bundle-nonmacro.check
deleted file mode 100644
index 5a265b5724..0000000000
--- a/test/files/neg/macro-bundle-nonmacro.check
+++ /dev/null
@@ -1,4 +0,0 @@
-macro-bundle-nonmacro.scala:8: error: not found: value Bundle
- def foo = Bundle.impl
- ^
-one error found
diff --git a/test/files/neg/macro-bundle-object.scala b/test/files/neg/macro-bundle-object.scala
index 02278e7165..6e1eec1686 100644
--- a/test/files/neg/macro-bundle-object.scala
+++ b/test/files/neg/macro-bundle-object.scala
@@ -1,7 +1,7 @@
import scala.language.experimental.macros
-import scala.reflect.macros.blackbox._
+import scala.reflect.macros.blackbox.Context
-object Bundle extends Macro {
+object Bundle {
val c: Context = ???
def impl = ???
}
diff --git a/test/files/neg/macro-bundle-polymorphic.check b/test/files/neg/macro-bundle-polymorphic.check
deleted file mode 100644
index 8eedce7e87..0000000000
--- a/test/files/neg/macro-bundle-polymorphic.check
+++ /dev/null
@@ -1,10 +0,0 @@
-macro-bundle-polymorphic.scala:9: error: macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member
- def foo = macro Bundle.impl
- ^
-macro-bundle-polymorphic.scala:10: error: macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member
- def foo = macro Bundle[Int].impl
- ^
-macro-bundle-polymorphic.scala:11: error: macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member
- def foo = macro Bundle[Int, Nothing].impl
- ^
-three errors found
diff --git a/test/files/neg/macro-bundle-polymorphic.scala b/test/files/neg/macro-bundle-polymorphic.scala
deleted file mode 100644
index b636b6bd6a..0000000000
--- a/test/files/neg/macro-bundle-polymorphic.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-import scala.language.experimental.macros
-import scala.reflect.macros.blackbox.Macro
-
-trait Bundle[T] extends Macro {
- def impl = ???
-}
-
-object Macros {
- def foo = macro Bundle.impl
- def foo = macro Bundle[Int].impl
- def foo = macro Bundle[Int, Nothing].impl
-} \ No newline at end of file
diff --git a/test/files/neg/macro-bundle-trait.check b/test/files/neg/macro-bundle-trait.check
index d7363fc361..869c67e1e3 100644
--- a/test/files/neg/macro-bundle-trait.check
+++ b/test/files/neg/macro-bundle-trait.check
@@ -1,4 +1,4 @@
-macro-bundle-trait.scala:10: error: macro bundles must be monomorphic traits extending either blackbox.Macro or whitebox.Macro and not implementing their `val c: Context` member
+macro-bundle-trait.scala:10: error: not found: value Bundle
def foo = macro Bundle.impl
^
one error found
diff --git a/test/files/neg/macro-bundle-trait.scala b/test/files/neg/macro-bundle-trait.scala
index 0d01459f7e..2aa63216f5 100644
--- a/test/files/neg/macro-bundle-trait.scala
+++ b/test/files/neg/macro-bundle-trait.scala
@@ -1,7 +1,7 @@
import scala.language.experimental.macros
-import scala.reflect.macros.blackbox._
+import scala.reflect.macros.blackbox.Context
-trait Bundle extends Macro {
+trait Bundle {
val c: Context = ???
def impl = ???
}
diff --git a/test/files/neg/macro-quasiquotes/Macros_1.scala b/test/files/neg/macro-quasiquotes/Macros_1.scala
index 7bfdbaeef9..b123c475c2 100644
--- a/test/files/neg/macro-quasiquotes/Macros_1.scala
+++ b/test/files/neg/macro-quasiquotes/Macros_1.scala
@@ -1,7 +1,7 @@
import language.experimental.macros
-import scala.reflect.macros.blackbox.Macro
+import scala.reflect.macros.blackbox.Context
-trait Impls extends Macro {
+class Impls(val c: Context) {
import c.universe._
def impl1(x: Expr[Int]) = q"println(x)"
def impl2(x: Tree) = q"println(x)"
diff --git a/test/files/run/macro-bundle-repl.check b/test/files/run/macro-bundle-repl.check
index e5456c411b..4a0b421606 100644
--- a/test/files/run/macro-bundle-repl.check
+++ b/test/files/run/macro-bundle-repl.check
@@ -4,17 +4,17 @@ Type :help for more information.
scala> import scala.language.experimental.macros
import scala.language.experimental.macros
-scala> import scala.reflect.macros.blackbox.Macro
-import scala.reflect.macros.blackbox.Macro
+scala> import scala.reflect.macros.blackbox.Context
+import scala.reflect.macros.blackbox.Context
-scala> trait Bar extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar: Unit = macro Bar.impl
-defined trait Bar
+scala> class Bar(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar: Unit = macro Bar.impl
+defined class Bar
defined term macro bar: Unit
scala> bar
-scala> trait Foo extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } }
-defined trait Foo
+scala> class Foo(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } }
+defined class Foo
scala> def foo: Unit = macro Foo.impl
defined term macro foo: Unit
diff --git a/test/files/run/macro-bundle-repl.scala b/test/files/run/macro-bundle-repl.scala
index 4dfd450b69..8084418454 100644
--- a/test/files/run/macro-bundle-repl.scala
+++ b/test/files/run/macro-bundle-repl.scala
@@ -3,10 +3,10 @@ import scala.tools.partest.ReplTest
object Test extends ReplTest {
def code = """
import scala.language.experimental.macros
-import scala.reflect.macros.blackbox.Macro
-trait Bar extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar: Unit = macro Bar.impl
+import scala.reflect.macros.blackbox.Context
+class Bar(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar: Unit = macro Bar.impl
bar
-trait Foo extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } }
+class Foo(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } }
def foo: Unit = macro Foo.impl
foo
"""
diff --git a/test/files/run/macro-bundle-static/Impls_Macros_1.scala b/test/files/run/macro-bundle-static/Impls_Macros_1.scala
index 34328edcd8..0142e5d945 100644
--- a/test/files/run/macro-bundle-static/Impls_Macros_1.scala
+++ b/test/files/run/macro-bundle-static/Impls_Macros_1.scala
@@ -1,8 +1,8 @@
-import scala.reflect.macros.blackbox.Macro
+import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
object Enclosing {
- trait Impl extends Macro {
+ class Impl(val c: Context) {
def mono = { import c.universe._; c.Expr[Unit](q"()") }
def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") }
def weird = macro mono
@@ -16,7 +16,7 @@ object Macros {
package pkg {
object Enclosing {
- trait Impl extends Macro {
+ class Impl(val c: Context) {
def mono = { import c.universe._; c.Expr[Boolean](q"true") }
def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") }
def weird = macro mono
diff --git a/test/files/run/macro-bundle-static/Test_2.scala b/test/files/run/macro-bundle-static/Test_2.scala
index 72160f6ec2..e35260cdce 100644
--- a/test/files/run/macro-bundle-static/Test_2.scala
+++ b/test/files/run/macro-bundle-static/Test_2.scala
@@ -1,8 +1,8 @@
object Test extends App {
println(Macros.mono)
println(Macros.poly[Int])
- println(new Enclosing.Impl{val c = ???}.weird)
+ println(new Enclosing.Impl(???).weird)
println(pkg.Macros.mono)
println(pkg.Macros.poly[Int])
- println(new pkg.Enclosing.Impl{val c = ???}.weird)
+ println(new pkg.Enclosing.Impl(???).weird)
} \ No newline at end of file
diff --git a/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala b/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala
index aa71346889..6fd7be3b25 100644
--- a/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala
+++ b/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala
@@ -1,6 +1,6 @@
-import scala.reflect.macros.blackbox.Macro
+import scala.reflect.macros.blackbox.Context
-trait Impl extends Macro {
+class Impl(val c: Context) {
def mono = { import c.universe._; c.Expr[Unit](q"()") }
def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") }
def weird = macro mono
@@ -12,7 +12,7 @@ object Macros {
}
package pkg {
- trait Impl extends Macro {
+ class Impl(val c: Context) {
def mono = { import c.universe._; c.Expr[Boolean](q"true") }
def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") }
def weird = macro mono
diff --git a/test/files/run/macro-bundle-toplevel/Test_2.scala b/test/files/run/macro-bundle-toplevel/Test_2.scala
index 139cc5bef2..195fb49262 100644
--- a/test/files/run/macro-bundle-toplevel/Test_2.scala
+++ b/test/files/run/macro-bundle-toplevel/Test_2.scala
@@ -1,8 +1,8 @@
object Test extends App {
println(Macros.mono)
println(Macros.poly[Int])
- println(new Impl{val c = ???}.weird)
+ println(new Impl(???).weird)
println(pkg.Macros.mono)
println(pkg.Macros.poly[Int])
- println(new pkg.Impl{val c = ???}.weird)
+ println(new pkg.Impl(???).weird)
} \ No newline at end of file
diff --git a/test/files/run/macro-bundle-whitebox.check b/test/files/run/macro-bundle-whitebox.check
new file mode 100644
index 0000000000..37c8eaf27a
--- /dev/null
+++ b/test/files/run/macro-bundle-whitebox.check
@@ -0,0 +1,6 @@
+()
+Int
+()
+true
+IntInt
+true
diff --git a/test/files/run/macro-bundle-whitebox/Impls_Macros_1.scala b/test/files/run/macro-bundle-whitebox/Impls_Macros_1.scala
new file mode 100644
index 0000000000..5e1b11895d
--- /dev/null
+++ b/test/files/run/macro-bundle-whitebox/Impls_Macros_1.scala
@@ -0,0 +1,26 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.whitebox.Context
+
+class Impl(val c: Context) {
+ def mono = { import c.universe._; c.Expr[Unit](q"()") }
+ def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") }
+ def weird = macro mono
+}
+
+object Macros {
+ def mono = macro Impl.mono
+ def poly[T] = macro Impl.poly[T]
+}
+
+package pkg {
+ class Impl(val c: Context) {
+ def mono = { import c.universe._; c.Expr[Boolean](q"true") }
+ def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") }
+ def weird = macro mono
+ }
+
+ object Macros {
+ def mono = macro Impl.mono
+ def poly[T] = macro Impl.poly[T]
+ }
+} \ No newline at end of file
diff --git a/test/files/run/macro-bundle-whitebox/Test_2.scala b/test/files/run/macro-bundle-whitebox/Test_2.scala
new file mode 100644
index 0000000000..195fb49262
--- /dev/null
+++ b/test/files/run/macro-bundle-whitebox/Test_2.scala
@@ -0,0 +1,8 @@
+object Test extends App {
+ println(Macros.mono)
+ println(Macros.poly[Int])
+ println(new Impl(???).weird)
+ println(pkg.Macros.mono)
+ println(pkg.Macros.poly[Int])
+ println(new pkg.Impl(???).weird)
+} \ No newline at end of file
diff --git a/test/files/run/macro-quasiquotes/Macros_1.scala b/test/files/run/macro-quasiquotes/Macros_1.scala
index 9e0f4ec0db..764542a870 100644
--- a/test/files/run/macro-quasiquotes/Macros_1.scala
+++ b/test/files/run/macro-quasiquotes/Macros_1.scala
@@ -1,7 +1,7 @@
import language.experimental.macros
-import scala.reflect.macros.blackbox.Macro
+import scala.reflect.macros.blackbox.Context
-trait Impls extends Macro {
+class Impls(val c: Context) {
import c.universe._
def impl1 = q"println(1)"
def impl2 = q"{ println(2); println(3) }"