diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-12-11 15:56:37 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-12-11 20:06:08 +0100 |
commit | 0304e00168393d47e18dbb4d2c634d51bab1383a (patch) | |
tree | 191643e52a25845360767433364b41d9de091ef6 /test/files/pos/t6780.scala | |
parent | b345b42cac64aa97e3bbcc6f14ef8f08214ab56f (diff) | |
download | scala-0304e00168393d47e18dbb4d2c634d51bab1383a.tar.gz scala-0304e00168393d47e18dbb4d2c634d51bab1383a.tar.bz2 scala-0304e00168393d47e18dbb4d2c634d51bab1383a.zip |
SI-6780 Better handling of cycles in in-scope implicit search
Implicit searches in the body of implicit members with inferred
types were leading to cycles. Before we used to resolve that
by saying there were no implicits in scope at all; now we just
skip the current context and still include the enclosing implicits.
Care is taken not to cache results under these circumstances.
This entails reworking `Context#implicitss` so that:
- the implicit info cache only contains implicits from the current
level. The List[List[_]] is now contructed on demand;
- we can detect cycles by setting `implicitsCacheRunId` to -1 during
the computation. The outer implicits when we encounter that.
- we avoid caching when we hit a cycle or when the owner is uninitialized.
Diffstat (limited to 'test/files/pos/t6780.scala')
-rw-r--r-- | test/files/pos/t6780.scala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/files/pos/t6780.scala b/test/files/pos/t6780.scala new file mode 100644 index 0000000000..4a358046c6 --- /dev/null +++ b/test/files/pos/t6780.scala @@ -0,0 +1,20 @@ +object O { + implicit def i: Int = 0 +} + +import O._ + +trait Foo { + implicit val v1: Any + implicit def d1: Any + val v2: Any + implicit val v3: Any +} + +trait Bar1 extends Foo { + implicit val v1 = {implicitly[Int]; ()} // failed due to cycle in Context#implicits being broken with Nil. + def d1 = {implicitly[Int]; ()} // okay + implicit val v2 = {implicitly[Int]; ()} // okay + implicit val v3: Any = {implicitly[Int]; ()} // okay + +} |