Skip to content
Browse files

changes bundles to be classes, not traits extending Macro

Adjusts bundle notation to read `class Bundle(val c: Context)` instead of
`class Bundle extends Macro`. This avoids calling compileLate in the
macro compiler and associated tooling problems.
  • Loading branch information...
1 parent 5cc8f83 commit 3a689f5c426436aea716567625fd6167e57bef92 @xeno-by xeno-by committed Jan 12, 2014
Showing with 108 additions and 251 deletions.
  1. +1 −1 src/compiler/scala/reflect/macros/compiler/Errors.scala
  2. +5 −30 src/compiler/scala/reflect/macros/compiler/Resolvers.scala
  3. +3 −3 src/compiler/scala/reflect/macros/compiler/Validators.scala
  4. +2 −2 src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala
  5. +0 −19 src/compiler/scala/tools/nsc/Global.scala
  6. +19 −25 src/reflect/scala/reflect/internal/Definitions.scala
  7. +0 −40 src/reflect/scala/reflect/macros/blackbox/Macro.scala
  8. +0 −40 src/reflect/scala/reflect/macros/whitebox/Macro.scala
  9. +0 −2 src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
  10. +3 −3 test/files/neg/macro-bundle-abstract.check
  11. +2 −2 test/files/neg/macro-bundle-abstract.scala
  12. +0 −4 test/files/neg/macro-bundle-class.check
  13. +0 −10 test/files/neg/macro-bundle-class.scala
  14. +0 −4 test/files/neg/macro-bundle-mixbox.check
  15. +0 −11 test/files/neg/macro-bundle-mixbox.scala
  16. +4 −0 test/files/neg/macro-bundle-noncontext.check
  17. +1 −1 test/files/neg/{macro-bundle-nonmacro.scala → macro-bundle-noncontext.scala}
  18. +0 −4 test/files/neg/macro-bundle-nonmacro.check
  19. +2 −2 test/files/neg/macro-bundle-object.scala
  20. +0 −10 test/files/neg/macro-bundle-polymorphic.check
  21. +0 −12 test/files/neg/macro-bundle-polymorphic.scala
  22. +1 −1 test/files/neg/macro-bundle-trait.check
  23. +2 −2 test/files/neg/macro-bundle-trait.scala
  24. +2 −2 test/files/neg/macro-quasiquotes/Macros_1.scala
  25. +6 −6 test/files/run/macro-bundle-repl.check
  26. +3 −3 test/files/run/macro-bundle-repl.scala
  27. +3 −3 test/files/run/macro-bundle-static/Impls_Macros_1.scala
  28. +2 −2 test/files/run/macro-bundle-static/Test_2.scala
  29. +3 −3 test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala
  30. +2 −2 test/files/run/macro-bundle-toplevel/Test_2.scala
  31. +6 −0 test/files/run/macro-bundle-whitebox.check
  32. +26 −0 test/files/run/macro-bundle-whitebox/Impls_Macros_1.scala
  33. +8 −0 test/files/run/macro-bundle-whitebox/Test_2.scala
  34. +2 −2 test/files/run/macro-quasiquotes/Macros_1.scala
View
2 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
View
35 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
}
View
6 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() = {
View
4 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]]: _*)
View
19 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?)
*/
View
44 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
View
40 src/reflect/scala/reflect/macros/blackbox/Macro.scala
@@ -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
-}
View
40 src/reflect/scala/reflect/macros/whitebox/Macro.scala
@@ -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
-}
View
2 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
View
6 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
View
4 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 = ???
}
View
4 test/files/neg/macro-bundle-class.check
@@ -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
View
10 test/files/neg/macro-bundle-class.scala
@@ -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
-}
View
4 test/files/neg/macro-bundle-mixbox.check
@@ -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
View
11 test/files/neg/macro-bundle-mixbox.scala
@@ -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
-}
View
4 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
View
2 test/files/neg/macro-bundle-nonmacro.scala → test/files/neg/macro-bundle-noncontext.scala
@@ -1,6 +1,6 @@
import scala.language.experimental.macros
-trait Bundle {
+class Bundle {
def impl = ???
}
View
4 test/files/neg/macro-bundle-nonmacro.check
@@ -1,4 +0,0 @@
-macro-bundle-nonmacro.scala:8: error: not found: value Bundle
- def foo = Bundle.impl
- ^
-one error found
View
4 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 = ???
}
View
10 test/files/neg/macro-bundle-polymorphic.check
@@ -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
View
12 test/files/neg/macro-bundle-polymorphic.scala
@@ -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
-}
View
2 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
View
4 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 = ???
}
View
4 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)"
View
12 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
View
6 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
"""
View
6 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
View
4 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)
}
View
6 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
View
4 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)
}
View
6 test/files/run/macro-bundle-whitebox.check
@@ -0,0 +1,6 @@
+()
+Int
+()
+true
+IntInt
+true
View
26 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]
+ }
+}
View
8 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)
+}
View
4 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) }"

0 comments on commit 3a689f5

Please sign in to comment.
Something went wrong with that request. Please try again.