Skip to content

StackOverflowError related to implicits #6119

@liufengyun

Description

@liufengyun

The following code is minimized from ScalaTest, which compiles fine in Scala 2.12.8, but causes a stackoverflow in Dotty:

class Test {
  def to[Col[_]](factory: Factory[Int, Col[Int]]): Col[Int] = ???

  to(Vector)

  type Factory[-A, +C] = scala.collection.generic.CanBuildFrom[Nothing, A, C] // Ideally, this would be an opaque type

  implicit def fromCanBuildFromConversion[X, A, C](x: X)(
    implicit toCanBuildFrom: X => scala.collection.generic.CanBuildFrom[Nothing, A, C]): Factory[A, C] = ???

  implicit def genericCompanionToCBF[A, CC[X] <: scala.collection.GenTraversable[X]](
    fact: scala.collection.generic.GenericCompanion[CC]): scala.collection.generic.CanBuildFrom[Any, A, CC[A]] = ???
}

Note that in the above, if we comment out fromCanBuildFromConversion, it compiles both in Scala 2.12.8 and Dotty.

This seems to be the culprit of a compiler hang when working with a test in Scalactic.

Chain(1, 2, 3).to(Vector) shouldBe Vector(1, 2, 3)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions