summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-02-23 14:34:29 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-05-11 18:37:11 +0200
commit3edde2727bad9b00cbaf5475f5bf234f08c26cbd (patch)
tree417c7e1b2ed785bcf01ee7d1b8e42fbdaa4a6d92 /test
parentb4da864247ccaaee4f987fbf433b312e1d744a8f (diff)
downloadscala-3edde2727bad9b00cbaf5475f5bf234f08c26cbd.tar.gz
scala-3edde2727bad9b00cbaf5475f5bf234f08c26cbd.tar.bz2
scala-3edde2727bad9b00cbaf5475f5bf234f08c26cbd.zip
[nomaster] SI-7166 catches DivergentImplicit in c.inferImplicitXXX
Despite inferImplicit usually being nice and buffering errors, apparently it can also throw DivergentImplicit exception. This patch catches it and only reports it if silent is set to false. NOTE: we no longer have the DivergentImplicit exception in master, so this commit only makes sense in 2.10.x.
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/t7166.check4
-rw-r--r--test/files/neg/t7166/Impls_Macros_1.scala26
-rw-r--r--test/files/neg/t7166/Test_2.scala3
3 files changed, 33 insertions, 0 deletions
diff --git a/test/files/neg/t7166.check b/test/files/neg/t7166.check
new file mode 100644
index 0000000000..c87198cb27
--- /dev/null
+++ b/test/files/neg/t7166.check
@@ -0,0 +1,4 @@
+Test_2.scala:2: error: silent = true does work!
+ println(implicitly[Complex[Foo]])
+ ^
+one error found
diff --git a/test/files/neg/t7166/Impls_Macros_1.scala b/test/files/neg/t7166/Impls_Macros_1.scala
new file mode 100644
index 0000000000..62a15657c3
--- /dev/null
+++ b/test/files/neg/t7166/Impls_Macros_1.scala
@@ -0,0 +1,26 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+trait Complex[T]
+
+class Foo
+
+object Complex {
+ def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = {
+ import c.universe._
+ def shout(msg: String) = {
+ val cannotShutMeUp = c.asInstanceOf[scala.reflect.macros.runtime.Context].universe.currentRun.currentUnit.error _
+ cannotShutMeUp(c.enclosingPosition.asInstanceOf[scala.reflect.internal.util.Position], msg)
+ }
+ try {
+ val complexOfT = appliedType(typeOf[Complex[_]], List(weakTypeOf[T]))
+ val infiniteRecursion = c.inferImplicitValue(complexOfT, silent = true)
+ shout("silent = true does work!")
+ } catch {
+ case ex: Exception => shout(ex.toString)
+ }
+ c.literalNull
+ }
+
+ implicit def genComplex[T]: Complex[T] = macro impl[T]
+}
diff --git a/test/files/neg/t7166/Test_2.scala b/test/files/neg/t7166/Test_2.scala
new file mode 100644
index 0000000000..dcc4593335
--- /dev/null
+++ b/test/files/neg/t7166/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ println(implicitly[Complex[Foo]])
+} \ No newline at end of file