summaryrefslogtreecommitdiff
path: root/test/files/run/macro-divergence-spurious
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-02-23 13:40:14 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-05-12 22:19:02 +0200
commitc539ae2f56fe9f565cffb4afd6ab131bda89acb7 (patch)
tree30c9472e80b9732b713ab0efa0c148827808276f /test/files/run/macro-divergence-spurious
parenta35b6bc8e4369db8983d6d0d9881f37d7affbadd (diff)
downloadscala-c539ae2f56fe9f565cffb4afd6ab131bda89acb7.tar.gz
scala-c539ae2f56fe9f565cffb4afd6ab131bda89acb7.tar.bz2
scala-c539ae2f56fe9f565cffb4afd6ab131bda89acb7.zip
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`.
Diffstat (limited to 'test/files/run/macro-divergence-spurious')
-rw-r--r--test/files/run/macro-divergence-spurious/Impls_Macros_1.scala23
-rw-r--r--test/files/run/macro-divergence-spurious/Test_2.scala3
2 files changed, 26 insertions, 0 deletions
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