diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-10-02 17:21:27 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-11-12 18:40:01 -0800 |
commit | a2b523a39b4e56eb9ab5d9a5639f5b59d425e354 (patch) | |
tree | 8d91dd18059b1166d9e7d3ee6a1ab22166d0ae7b /test/files/run | |
parent | ce37ae45e22463a3f1a2d659d6699f2977b26c6b (diff) | |
download | scala-a2b523a39b4e56eb9ab5d9a5639f5b59d425e354.tar.gz scala-a2b523a39b4e56eb9ab5d9a5639f5b59d425e354.tar.bz2 scala-a2b523a39b4e56eb9ab5d9a5639f5b59d425e354.zip |
blackbox restriction #1: can't refine the official return type
When an application of a blackbox macro expands into a tree `x`,
the expansion is wrapped into a type ascription `(x: T)`, where `T` is
the declared return type of the blackbox macro with type arguments and
path dependencies applied in consistency with the particular macro
application being expanded.
This invalidates blackbox macros as an implementation vehicle
of type providers.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/macro-bodyexpandstoimpl/Impls_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/macro-invalidusage-badret.check | 2 | ||||
-rw-r--r-- | test/files/run/macro-system-properties.check | 6 | ||||
-rw-r--r-- | test/files/run/macro-whitebox-structural.check | 1 | ||||
-rw-r--r-- | test/files/run/macro-whitebox-structural/Impls_Macros_1.scala | 16 | ||||
-rw-r--r-- | test/files/run/macro-whitebox-structural/Test_2.scala | 5 | ||||
-rw-r--r-- | test/files/run/t5903a/Macros_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5903b/Macros_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5903c/Macros_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5903d/Macros_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5923a/Macros_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5923c/Macros_1.scala | 4 |
13 files changed, 45 insertions, 17 deletions
diff --git a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala index 9af3b18ccb..0a9f9a0ced 100644 --- a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala +++ b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala @@ -1,11 +1,11 @@ import scala.language.experimental.macros -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.{BlackboxContext, WhiteboxContext} object Impls { def foo(c: BlackboxContext)(x: c.Expr[Int]) = x def refToFoo(dummy: Int) = macro refToFoo_impl - def refToFoo_impl(c: BlackboxContext)(dummy: c.Expr[Int]) = { + def refToFoo_impl(c: WhiteboxContext)(dummy: c.Expr[Int]) = { import c.universe._ val body = Select(Ident(TermName("Impls")), TermName("foo")) val global = c.universe.asInstanceOf[scala.tools.nsc.Global] diff --git a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala index b837ffc43b..7bfff374e2 100644 --- a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala +++ b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala @@ -1,11 +1,11 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext object Helper { def unapplySeq[T](x: List[T]): Option[Seq[T]] = List.unapplySeq[T](x) } object Macros { - def impl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[List[T]]) = { + def impl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Expr[List[T]]) = { c.universe.reify(Helper.unapplySeq(x.splice)) } diff --git a/test/files/run/macro-invalidusage-badret.check b/test/files/run/macro-invalidusage-badret.check index 9225b716d6..e79550043f 100644 --- a/test/files/run/macro-invalidusage-badret.check +++ b/test/files/run/macro-invalidusage-badret.check @@ -1,5 +1,5 @@ reflective compilation has failed: type mismatch; - found : Int(42) + found : Int required: String diff --git a/test/files/run/macro-system-properties.check b/test/files/run/macro-system-properties.check index ea4c5a664a..b102d319ec 100644 --- a/test/files/run/macro-system-properties.check +++ b/test/files/run/macro-system-properties.check @@ -14,9 +14,15 @@ scala> object GrabContext { defined object GrabContext scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +<console>:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + object Test { class C(implicit a: Any) { GrabContext.grab } } + ^ defined object Test scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +<console>:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + object Test { class C(implicit a: Any) { GrabContext.grab } } + ^ defined object Test scala> diff --git a/test/files/run/macro-whitebox-structural.check b/test/files/run/macro-whitebox-structural.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/run/macro-whitebox-structural.check @@ -0,0 +1 @@ +2 diff --git a/test/files/run/macro-whitebox-structural/Impls_Macros_1.scala b/test/files/run/macro-whitebox-structural/Impls_Macros_1.scala new file mode 100644 index 0000000000..1b975ca850 --- /dev/null +++ b/test/files/run/macro-whitebox-structural/Impls_Macros_1.scala @@ -0,0 +1,16 @@ +import scala.reflect.macros.WhiteboxContext +import scala.language.experimental.macros + +object Macros { + def impl(c: WhiteboxContext) = { + import c.universe._ + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } + + def foo = macro impl +}
\ No newline at end of file diff --git a/test/files/run/macro-whitebox-structural/Test_2.scala b/test/files/run/macro-whitebox-structural/Test_2.scala new file mode 100644 index 0000000000..ea6a817e34 --- /dev/null +++ b/test/files/run/macro-whitebox-structural/Test_2.scala @@ -0,0 +1,5 @@ +import Macros._ + +object Test extends App { + println(Macros.foo.x) +}
\ No newline at end of file diff --git a/test/files/run/t5903a/Macros_1.scala b/test/files/run/t5903a/Macros_1.scala index 9fc3bfe261..7888b888e1 100644 --- a/test/files/run/t5903a/Macros_1.scala +++ b/test/files/run/t5903a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros trait Tree @@ -13,7 +13,7 @@ object NewQuasiquotes { } object QuasiquoteMacros { - def unapplyImpl(c: BlackboxContext)(t: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(t: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903b/Macros_1.scala b/test/files/run/t5903b/Macros_1.scala index ae491e2207..8c03e5579d 100644 --- a/test/files/run/t5903b/Macros_1.scala +++ b/test/files/run/t5903b/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903c/Macros_1.scala b/test/files/run/t5903c/Macros_1.scala index da7dd5281c..c9dfe9d60c 100644 --- a/test/files/run/t5903c/Macros_1.scala +++ b/test/files/run/t5903c/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903d/Macros_1.scala b/test/files/run/t5903d/Macros_1.scala index e3a9c3b39e..8a57e27602 100644 --- a/test/files/run/t5903d/Macros_1.scala +++ b/test/files/run/t5903d/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5923a/Macros_1.scala b/test/files/run/t5923a/Macros_1.scala index f86e6b1add..445392ff95 100644 --- a/test/files/run/t5923a/Macros_1.scala +++ b/test/files/run/t5923a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros case class C[T](t: String) @@ -7,7 +7,7 @@ object C { } object Macros { - def impl[T](c: BlackboxContext)(ttag: c.WeakTypeTag[T]) = { + def impl[T](c: WhiteboxContext)(ttag: c.WeakTypeTag[T]) = { import c.universe._ val ttag0 = ttag; { diff --git a/test/files/run/t5923c/Macros_1.scala b/test/files/run/t5923c/Macros_1.scala index c980f243d4..c86e14966b 100644 --- a/test/files/run/t5923c/Macros_1.scala +++ b/test/files/run/t5923c/Macros_1.scala @@ -1,5 +1,5 @@ import language.experimental.macros -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext trait Iso[T, U] { def to(t : T) : U @@ -8,7 +8,7 @@ trait Iso[T, U] { object Iso { implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] - def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: BlackboxContext): c.Expr[Iso[T, U]] = { + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: WhiteboxContext): c.Expr[Iso[T, U]] = { import c.universe._ import definitions._ import Flag._ |