Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SI-6535 Step back from the precipice of a cycle
Adding any non-local parent to WrapAsScala will trigger a valid
cyclic reference error. By moving the import of `Wrapper._`
inside `WrapAsScala` and `WrapAsJava`, it is not in scope when
typing the parents of those, and we avoid the cycle.

Adds a test case to show the essense of the promiscious mutual
imports that triggers this.
  • Loading branch information
retronym committed Dec 4, 2012
1 parent fd57069 commit 8a1f85d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/library/scala/collection/convert/WrapAsJava.scala
Expand Up @@ -10,10 +10,11 @@ package scala.collection
package convert

import java.{ lang => jl, util => ju }, java.util.{ concurrent => juc }
import Wrappers._
import scala.language.implicitConversions

trait WrapAsJava {
import Wrappers._

/**
* Implicitly converts a Scala Iterator to a Java Iterator.
* The returned Java Iterator is backed by the provided Scala
Expand Down
5 changes: 4 additions & 1 deletion src/library/scala/collection/convert/WrapAsScala.scala
Expand Up @@ -10,11 +10,13 @@ package scala.collection
package convert

import java.{ lang => jl, util => ju }, java.util.{ concurrent => juc }
import Wrappers._
import scala.language.implicitConversions

trait LowPriorityWrapAsScala {
this: WrapAsScala =>

import Wrappers._

/**
* Implicitly converts a Java ConcurrentMap to a Scala mutable ConcurrentMap.
* The returned Scala ConcurrentMap is backed by the provided Java
Expand All @@ -34,6 +36,7 @@ trait LowPriorityWrapAsScala {
}

trait WrapAsScala extends LowPriorityWrapAsScala {
import Wrappers._
/**
* Implicitly converts a Java `Iterator` to a Scala `Iterator`.
*
Expand Down
6 changes: 6 additions & 0 deletions test/files/neg/t6535.check
@@ -0,0 +1,6 @@
t6535.scala:2: error: encountered unrecoverable cycle resolving import.
Note: this is often due in part to a class depending on a definition nested within its companion.
If applicable, you may wish to try moving some members into another object.
import Bs.B._
^
one error found
15 changes: 15 additions & 0 deletions test/files/neg/t6535.scala
@@ -0,0 +1,15 @@
object As {
import Bs.B._

object A
extends scala.AnyRef // needed for the cycle;
// replacing with a locally defined closs doesn't
// hit the locked import and hence doesn't cycle.
}

object Bs {
import As.A._

object B
extends scala.AnyRef // scala.Immutable, ...
}

0 comments on commit 8a1f85d

Please sign in to comment.