From c539ae2f56fe9f565cffb4afd6ab131bda89acb7 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sat, 23 Feb 2013 13:40:14 +0100 Subject: SI-7167 implicit macros decide what is divergence This is a port of https://github.com/scala/scala/commit/8168f118c9 from 2.10.x, with an additional change to the `enclosingImplicits` and `openImplicits` APIs, which encapsulates tuples of `pt` and `tree` into `ImplicitCandidate`. --- .../macro-divergence-spurious/Impls_Macros_1.scala | 23 ++++++++++++++++++++++ .../run/macro-divergence-spurious/Test_2.scala | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 test/files/run/macro-divergence-spurious/Impls_Macros_1.scala create mode 100644 test/files/run/macro-divergence-spurious/Test_2.scala (limited to 'test/files/run/macro-divergence-spurious') diff --git a/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala new file mode 100644 index 0000000000..bc4a9fded7 --- /dev/null +++ b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.Context +import language.experimental.macros + +trait Complex[T] + +class Foo(val bar: Bar) +class Bar(val s: String) + +object Complex { + def impl[T: c.WeakTypeTag](c: Context): 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}) { + val trecur = appliedType(typeOf[Complex[_]], List(f.typeSignature)) + val recur = c.inferImplicitValue(trecur, silent = true) + if (recur == EmptyTree) c.abort(c.enclosingPosition, s"couldn't synthesize $trecur") + } + c.literalNull + } + + implicit object ComplexString extends Complex[String] + implicit def genComplex[T]: Complex[T] = macro impl[T] +} diff --git a/test/files/run/macro-divergence-spurious/Test_2.scala b/test/files/run/macro-divergence-spurious/Test_2.scala new file mode 100644 index 0000000000..dcc4593335 --- /dev/null +++ b/test/files/run/macro-divergence-spurious/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + println(implicitly[Complex[Foo]]) +} \ No newline at end of file -- cgit v1.2.3