scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Non finitary class graph passes compiler check or an unwarranted infinite recursion in typer. #12412

Open noresttherein opened 3 years ago

noresttherein commented 3 years ago

reproduction steps

using Scala ~2.13.4~2.13.6,

    trait Chain
    class ~[I <: Chain, L] extends Chain
    class @~ extends Chain

    trait Factory[+R[_]] {
        def m[T]: R[T]
    }

    trait GenericExpansion[K <: Chain, E[_ <: Chain]] extends Factory[({ type R[X] = E[K ~ X] })#R]
    trait Instance[K <: Chain] extends GenericExpansion[K, Instance]

    trait FFactory[+R[_]] {
        def f[X]: R[X]
    }
    trait F extends FFactory[({ type R[X] = Instance[@~ ~ X] })#R]

    trait Test[X] {
        def m(x: X, y: X): X = m(x)
        def m(x: X): X = x
        def m(i: Int): F
    }

problem

If you comment out trait Test, everything seems ok. That is, except random pieces of code using F in completly legal ways you get a StackOverflowException. In Test, the problem is the m(x) call in presence of overloads of the same shape(?). In the original, the types weren't even generic, but unrelated. Should F compile at all? If not, is the whole problem approached by this code unsolvable in general?

SethTisue commented 3 years ago

Is the problem reproducible in Scala 2.13.6?

noresttherein commented 3 years ago

Yes, sorry.

SethTisue commented 3 years ago

@noresttherein how confident are you this is minimized?

fwiw, it does compile in Scala 3

Scala 2:

java.lang.StackOverflowError
    at scala.reflect.internal.Types$TypeRef.mapOver(Types.scala:2371)
    at scala.reflect.internal.Types$Type$$anon$1.apply(Types.scala:806)
    at scala.reflect.internal.Types$Type$$anon$1.apply(Types.scala:805)
    at scala.reflect.internal.Types$TypeRef.mapOver(Types.scala:2380)
...