scala / bug

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

Type aliases fool the check for non-finitary class graph #12603

Open noresttherein opened 2 years ago

noresttherein commented 2 years ago

Reproduction steps

Scala version: 2.13.8


object NonFinitary {
    trait BadJoke[V, +T]

    trait Root[V] extends Fog[V] //extends BadJoke[V, Another[V]]
    trait Another[V] extends Root[Option[V]]
    type Fog[V] = BadJoke[V, Another[V]]
}

Problem

Code above compiles. Type Root is however infinitely expansive, and this causes a StackOverflowError in an undertmined location. Which shouldn't be a problem, because it shouldn't compile in the first place.

SethTisue commented 2 years ago

Scala 3 (3.2.0-RC1-bin-20220604-13ce496-NIGHTLY) accepts it, too.

SethTisue commented 2 years ago

What's an example of how to trigger the SOE? (Asking mainly because I'm curious if the situation in Scala 3 is also the same there. I don't know if anyone is likely to dig into this in Scala 2, but the chances might be higher over on the Scala 3 side.)

dwijnand commented 2 years ago

You don't even need a type alias to "fool" the check:

class Foo[A]
class Bar[B] extends Foo[Bar[B]]

But I'm not convinced that's a problem.

SethTisue commented 2 years ago

which Scala 3 also accepts.

joroKr21 commented 2 years ago

If you uncomment //extends BadJoke[V, Another[V]] you get an error

dwijnand commented 2 years ago

It doesn't in Scala 3. The test in Scala 2 is checkFinitary and the closest I can see in Scala 3 is checkNonCyclicInherited, but I can't tell when it says "type members" whether or not that' meant to check type parameters too or not, which are more clearly definitely checked in the Scala 2 check. Run out of budget to investigate this one.