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/run/macro-whitebox-dynamic-materialization | |
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/run/macro-whitebox-dynamic-materialization')
-rw-r--r-- | test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala | 25 | ||||
-rw-r--r-- | test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala b/test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala new file mode 100644 index 0000000000..87cd310b09 --- /dev/null +++ b/test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.WhiteboxContext +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: WhiteboxContext) = { + 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/run/macro-whitebox-dynamic-materialization/Test_2.scala b/test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala new file mode 100644 index 0000000000..bf19209ab7 --- /dev/null +++ b/test/files/run/macro-whitebox-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 |