Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflow in implicit search (getParts) #11775

adriaanm opened this issue Oct 17, 2019 · 1 comment


Copy link

@adriaanm adriaanm commented Oct 17, 2019

trait Cmp[T] { def compareTo(o: T): Int }
class K[T] extends Cmp[K[_ >: T]] { def compareTo(that: K[_ >: T]): Int = ??? }

object Tst {
  (new K[String]).compareTo(new K[Int])

stack overflows in 2.13.x -- haven't checked older versions

+ marks the spot

--- i/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ w/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -1367,6 +1367,7 @@ trait Implicits {
       def getParts(tp: Type)(implicit infoMap: InfoMap, seen: mutable.HashSet[Type], pending: Set[Symbol]): Unit = {
         if (seen add tp) tp match {
+//          case _ if seen exists (_ =:= tp) => println(s"already had $tp in $seen")
           case TypeRef(pre, sym, args) =>
             if (sym.isClass && !sym.isRoot &&
                 (isScala213 || !sym.isAnonOrRefinementClass)) {

This comment has been minimized.

Copy link
Member Author

@adriaanm adriaanm commented Oct 17, 2019

uncommenting that quick fix (this is performance critical, so we can't just use =:=), you get the (expected) type error:

 type mismatch;
 found   : K[Int]
 required: K[_ >: String]
Note: Int <: Any, but class K is invariant in type T.
You may wish to define T as +T instead. (SLS 4.5)
  (new K[String]).compareTo(new K[Int])
one error found
@SethTisue SethTisue changed the title StackOverlow in implicit search (getParts) StackOverflow in implicit search (getParts) Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.