bug icon indicating copy to clipboard operation
bug copied to clipboard

Abstract type member instantiation causes illegal cyclic reference compile error

Open odipar opened this issue 6 years ago • 4 comments

The following code doesn't compile and cause 'illegal cyclic reference' compile error

object IllegalCyclicReference {

  trait Problem {
    def x: X

    // If we uncomment below , we get the compiler error "illegal cyclic reference" ????
    // def z = x.z
  }

  trait Y[S]

  trait X {
    type S = Z

    trait Z extends Y[S]

    def z: Z
  }
}

See also ScalaFiddle: https://scalafiddle.io/sf/zuBKhBy/5

odipar avatar Jun 06 '19 07:06 odipar

All major scala compiler (2.10, 2.11, 2.12) versions cause the error except Dotty.

odipar avatar Jun 06 '19 08:06 odipar

I see the label 'fixed in Dotty' but is it really 'fixed'?

It could well be that my construction is invalid and the none-Dotty compilers are correct...

odipar avatar Jun 06 '19 19:06 odipar

non-Dotty == scala 2.x.y

odipar avatar Jun 06 '19 19:06 odipar

That's awkward.

  • Moving Problem below X makes the error go away
  • So does ascribing def z: X#S = x.z
  • But ascribing def z: X#Z = x.z still fails

So I guess it depends on the order in which the types are completed.

joroKr21 avatar Jul 19 '19 00:07 joroKr21