diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-10-02 17:22:07 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-11-12 18:40:01 -0800 |
commit | 0d5c2f76ea30c6a45471dac635f035e931075453 (patch) | |
tree | 15f477eb256a65f2d260b940f1a3c9bed113a3db /test/files/neg | |
parent | 6038bac3513a834e67ab4074c2c7b03aac11b1b3 (diff) | |
download | scala-0d5c2f76ea30c6a45471dac635f035e931075453.tar.gz scala-0d5c2f76ea30c6a45471dac635f035e931075453.tar.bz2 scala-0d5c2f76ea30c6a45471dac635f035e931075453.zip |
blackbox restriction #3: can't affect implicit search
When an application of a blackbox macro is used as an implicit candidate,
no expansion is performed until the macro is selected as the result of
the implicit search.
This makes it impossible to dynamically calculate availability of
implicit macros.
Diffstat (limited to 'test/files/neg')
5 files changed, 36 insertions, 7 deletions
diff --git a/test/files/neg/macro-blackbox-dynamic-materialization.check b/test/files/neg/macro-blackbox-dynamic-materialization.check new file mode 100644 index 0000000000..f6c73f7edb --- /dev/null +++ b/test/files/neg/macro-blackbox-dynamic-materialization.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: I don't like classes that contain integers + println(implicitly[Foo[C1]]) + ^ +one error found diff --git a/test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala b/test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala new file mode 100644 index 0000000000..a00d195005 --- /dev/null +++ b/test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.BlackboxContext +import scala.language.experimental.macros + +trait Foo[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: Foo[T] = null +} + +object Foo extends LowPriority { + implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] +} + +object Macros { + def impl[T: c.WeakTypeTag](c: BlackboxContext) = { + import c.universe._ + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.typeSignature =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" + } +}
\ No newline at end of file diff --git a/test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala b/test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala new file mode 100644 index 0000000000..bf19209ab7 --- /dev/null +++ b/test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + println(implicitly[Foo[C1]]) + println(implicitly[Foo[C2]]) +}
\ No newline at end of file diff --git a/test/files/neg/macro-blackbox-fundep-materialization.check b/test/files/neg/macro-blackbox-fundep-materialization.check index a5a9b9a206..3c03064a2d 100644 --- a/test/files/neg/macro-blackbox-fundep-materialization.check +++ b/test/files/neg/macro-blackbox-fundep-materialization.check @@ -1,12 +1,8 @@ -Test_2.scala:7: Iso.materializeIso is not a valid implicit value for Iso[Test.Foo,L] because: -hasMatchingSymbol reported error: type mismatch; +Test_2.scala:7: error: type mismatch; found : Iso[Test.Foo,(Int, String, Boolean)] required: Iso[Test.Foo,Nothing] Note: (Int, String, Boolean) >: Nothing, but trait Iso is invariant in type U. You may wish to define U as -U instead. (SLS 4.5) val equiv = foo(Foo(23, "foo", true)) ^ -Test_2.scala:7: error: could not find implicit value for parameter iso: Iso[Test.Foo,L] - val equiv = foo(Foo(23, "foo", true)) - ^ one error found diff --git a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala index 23fcdd6445..9fb374800b 100644 --- a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala +++ b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros trait Complex[T] @@ -6,7 +6,7 @@ trait Complex[T] class Foo(val foo: Foo) object Complex { - def impl[T: c.WeakTypeTag](c: BlackboxContext): c.Expr[Complex[T]] = { + def impl[T: c.WeakTypeTag](c: WhiteboxContext): c.Expr[Complex[T]] = { import c.universe._ val tpe = weakTypeOf[T] for (f <- tpe.declarations.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) { |