bug icon indicating copy to clipboard operation
bug copied to clipboard

Type aliases fool the check for non-finitary class graph

Open noresttherein opened this issue 3 years ago • 6 comments

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.

noresttherein avatar Jun 05 '22 20:06 noresttherein

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

SethTisue avatar Jun 06 '22 20:06 SethTisue

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.)

SethTisue avatar Jun 30 '22 15:06 SethTisue

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.

dwijnand avatar Jun 30 '22 15:06 dwijnand

which Scala 3 also accepts.

SethTisue avatar Jun 30 '22 15:06 SethTisue

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

joroKr21 avatar Jul 01 '22 07:07 joroKr21

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.

dwijnand avatar Jul 01 '22 10:07 dwijnand