Skip to content

Missing cyclic reference check for method type parameter leads to stackoverflow #3882

Closed
@smarter

Description

@smarter
trait Ring[A <: Ring[A]]

object Test {
  def crash[T <: Ring[_ <: T]]: Ring[T] = ???
}

scalac:

error: illegal cyclic reference involving type T
  def crash[T <: Ring[_ <: T]]: Ring[T] = ???
                      ^

dotty:

Exception in thread "main" java.lang.StackOverflowError
        at dotty.tools.dotc.core.Types$TypeMap$$Lambda$238/1866161430.<init>(Unknown Source)
        at dotty.tools.dotc.core.Types$TypeMap$$Lambda$238/1866161430.get$Lambda(Unknown Source)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:3786)
        at dotty.tools.dotc.core.Substituters.subst1(Substituters.scala:35)
        at dotty.tools.dotc.core.Substituters.subst1$(Substituters.scala:24)
        at dotty.tools.dotc.core.Contexts$Context.subst1(Contexts.scala:67)
        at dotty.tools.dotc.core.Substituters$Subst1Map.apply(Substituters.scala:202)
        at dotty.tools.dotc.core.Types$TypeMap.$anonfun$mapOver$6(Types.scala:3811)
        at dotty.tools.dotc.core.Types$VariantTraversal.atVariance(Types.scala:3741)
        at dotty.tools.dotc.core.Types$TypeMap.mapArgs$1(Types.scala:3811)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:3819)
...

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