From fdead2b3793fd530e05331649e655576f30e59e9 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 19 Feb 2013 17:16:13 +0100 Subject: [nomaster] SI-7291: No exception throwing for diverging implicit expansion Since we don't throw exceptions for normal errors it was a bit odd that we don't do that for DivergingImplicit. As SI-7291 shows, the logic behind catching/throwing exception was broken for divergence. Instead of patching it, I rewrote the mechanism so that we now another SearchFailure type related to diverging expansion, similar to ambiguous implicit scenario. The logic to prevent diverging expansion from stopping the search had to be slightly adapted but works as usual. The upside is that we don't have to catch diverging implicit for example in the presentation compiler which was again showing that something was utterly broken with the exception approach. NOTE: This is a partial backport of https://github.com/scala/scala/pull/2428, with a fix for SI-7291, but without removal of error kinds (the former is absolutely necessary, while the latter is nice to have, but not a must, therefore I'm not risking porting it to 2.10.x). Also, the fix for SI-7291 is hidden behind a flag named -Xdivergence211 in order not to occasionally break the code, which relies on pre-fix behavior. --- test/files/neg/t696.check | 5 ----- test/files/neg/t696.scala | 6 ------ test/files/neg/t696a.check | 5 +++++ test/files/neg/t696a.flags | 0 test/files/neg/t696a.scala | 6 ++++++ test/files/neg/t696b.check | 9 +++++++++ test/files/neg/t696b.flags | 1 + test/files/neg/t696b.scala | 7 +++++++ test/files/run/t7291a.check | 1 + test/files/run/t7291a.flags | 0 test/files/run/t7291a.scala | 19 +++++++++++++++++++ test/files/run/t7291b.check | 2 ++ test/files/run/t7291b.flags | 1 + test/files/run/t7291b.scala | 19 +++++++++++++++++++ 14 files changed, 70 insertions(+), 11 deletions(-) delete mode 100644 test/files/neg/t696.check delete mode 100644 test/files/neg/t696.scala create mode 100644 test/files/neg/t696a.check create mode 100644 test/files/neg/t696a.flags create mode 100644 test/files/neg/t696a.scala create mode 100644 test/files/neg/t696b.check create mode 100644 test/files/neg/t696b.flags create mode 100644 test/files/neg/t696b.scala create mode 100644 test/files/run/t7291a.check create mode 100644 test/files/run/t7291a.flags create mode 100644 test/files/run/t7291a.scala create mode 100644 test/files/run/t7291b.check create mode 100644 test/files/run/t7291b.flags create mode 100644 test/files/run/t7291b.scala (limited to 'test/files') diff --git a/test/files/neg/t696.check b/test/files/neg/t696.check deleted file mode 100644 index ac26a864a5..0000000000 --- a/test/files/neg/t696.check +++ /dev/null @@ -1,5 +0,0 @@ -t696.scala:4: error: diverging implicit expansion for type TypeUtil0.Type[Any] -starting with method WithType in object TypeUtil0 - as[Any](null); - ^ -one error found diff --git a/test/files/neg/t696.scala b/test/files/neg/t696.scala deleted file mode 100644 index a06a32141a..0000000000 --- a/test/files/neg/t696.scala +++ /dev/null @@ -1,6 +0,0 @@ -object TypeUtil0 { - trait Type[+T]; - implicit def WithType[S,T](implicit tpeS : Type[S], tpeT : Type[T]) : Type[S with T] = null - as[Any](null); - def as[T](x : Any)(implicit tpe : Type[T]) = null; -} diff --git a/test/files/neg/t696a.check b/test/files/neg/t696a.check new file mode 100644 index 0000000000..490fc1a571 --- /dev/null +++ b/test/files/neg/t696a.check @@ -0,0 +1,5 @@ +t696a.scala:4: error: diverging implicit expansion for type TypeUtil0.Type[Any] +starting with method WithType in object TypeUtil0 + as[Any](null); + ^ +one error found diff --git a/test/files/neg/t696a.flags b/test/files/neg/t696a.flags new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/files/neg/t696a.scala b/test/files/neg/t696a.scala new file mode 100644 index 0000000000..a06a32141a --- /dev/null +++ b/test/files/neg/t696a.scala @@ -0,0 +1,6 @@ +object TypeUtil0 { + trait Type[+T]; + implicit def WithType[S,T](implicit tpeS : Type[S], tpeT : Type[T]) : Type[S with T] = null + as[Any](null); + def as[T](x : Any)(implicit tpe : Type[T]) = null; +} diff --git a/test/files/neg/t696b.check b/test/files/neg/t696b.check new file mode 100644 index 0000000000..fcdb5440d8 --- /dev/null +++ b/test/files/neg/t696b.check @@ -0,0 +1,9 @@ +t696b.scala:5: error: diverging implicit expansion for type TypeUtil0.Type[Any] +starting with method WithType in object TypeUtil0 + as[Any](null) + ^ +t696b.scala:6: error: diverging implicit expansion for type TypeUtil0.Type[X] +starting with method WithType in object TypeUtil0 + def foo[X]() = as[X](null) + ^ +two errors found diff --git a/test/files/neg/t696b.flags b/test/files/neg/t696b.flags new file mode 100644 index 0000000000..d564f2b1f8 --- /dev/null +++ b/test/files/neg/t696b.flags @@ -0,0 +1 @@ +-Xdivergence211 \ No newline at end of file diff --git a/test/files/neg/t696b.scala b/test/files/neg/t696b.scala new file mode 100644 index 0000000000..ca76f7ef6c --- /dev/null +++ b/test/files/neg/t696b.scala @@ -0,0 +1,7 @@ +object TypeUtil0 { + trait Type[+T] + implicit def WithType[S,T](implicit tpeS : Type[S], tpeT : Type[T]) : Type[S with T] = null + def as[T](x : Any)(implicit tpe : Type[T]) = null + as[Any](null) + def foo[X]() = as[X](null) +} diff --git a/test/files/run/t7291a.check b/test/files/run/t7291a.check new file mode 100644 index 0000000000..126faa15b4 --- /dev/null +++ b/test/files/run/t7291a.check @@ -0,0 +1 @@ +conjure diff --git a/test/files/run/t7291a.flags b/test/files/run/t7291a.flags new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/files/run/t7291a.scala b/test/files/run/t7291a.scala new file mode 100644 index 0000000000..4b7c4a4184 --- /dev/null +++ b/test/files/run/t7291a.scala @@ -0,0 +1,19 @@ +trait Fooable[T] +object Fooable { + implicit def conjure[T]: Fooable[T] = { + println("conjure") + new Fooable[T]{} + } + +} + +object Test { + implicit def traversable[T, Coll[_] <: Traversable[_]](implicit +elem: Fooable[T]): Fooable[Coll[T]] = { + println("traversable") + new Fooable[Coll[T]]{} + } + def main(args: Array[String]) { + implicitly[Fooable[List[Any]]] + } +} diff --git a/test/files/run/t7291b.check b/test/files/run/t7291b.check new file mode 100644 index 0000000000..c07ba986a3 --- /dev/null +++ b/test/files/run/t7291b.check @@ -0,0 +1,2 @@ +conjure +traversable diff --git a/test/files/run/t7291b.flags b/test/files/run/t7291b.flags new file mode 100644 index 0000000000..d564f2b1f8 --- /dev/null +++ b/test/files/run/t7291b.flags @@ -0,0 +1 @@ +-Xdivergence211 \ No newline at end of file diff --git a/test/files/run/t7291b.scala b/test/files/run/t7291b.scala new file mode 100644 index 0000000000..30c4261a81 --- /dev/null +++ b/test/files/run/t7291b.scala @@ -0,0 +1,19 @@ +trait Fooable[T] +object Fooable { + implicit def conjure[T]: Fooable[T] = { + println("conjure") + new Fooable[T]{} + } + +} + +object Test { + implicit def traversable[T, Coll[_] <: Traversable[_]](implicit +elem: Fooable[T]): Fooable[Coll[T]] = { + println("traversable") + new Fooable[Coll[T]]{} + } + def main(args: Array[String]) { + implicitly[Fooable[List[Any]]] + } +} -- cgit v1.2.3