Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"illegal cyclic reference" again #11963

Open
dubinsky opened this issue Apr 28, 2020 · 6 comments
Open

"illegal cyclic reference" again #11963

dubinsky opened this issue Apr 28, 2020 · 6 comments
Labels
Milestone

Comments

@dubinsky
Copy link

dubinsky commented Apr 28, 2020

reproduction steps

object IllegalCyclicReference {
  trait Number[S <: Numbers[S], N <: Number[S, N]] { this: N => }
  trait PointNumber[S <: Numbers[S]] extends Number[S, S#Point] {
    this: S#Point => } // Error No 1
  trait Numbers[S <: Numbers[S]] { this: S =>
    type Point <: PointNumber[S]
  }
  trait Times[S <: Times[S]] extends Numbers[S] { this: S =>
    override type Point <: PointNumber[S] with Number[S, S#Point]  // Error No 2
  }
  trait Angles extends Numbers[Angles] {
    override type Point = PointNumber[Angles]
  }
}

problem

With Scala 2.13.0, 2.13.1 and 2.13.2:

[Error No 1] ... illegal cyclic reference involving trait PointNumber
[Error No 2] ... illegal cyclic reference involving type Point

expectation

BUILD SUCCESSFUL

like with Scala 2.12.10 :)

I do not understand if this is related to #11640 (or #11734) or is actually illegal in Scala 2.13 (and Dotty). I wasn't able to find a work-around :(

@dubinsky
Copy link
Author

dubinsky commented Jun 19, 2020

I was thrilled when I realized that Scala can encode family polymorphism that Java can not;
even more so when I found out that this can be done for production-size code, with family members placed in separate files, not co-located in one trait or object, and not assembled with the cake pattern (ugh). Above error-producing snippet was extracted from a somewhat larger code base that crucially depends on such encoding.

It's been a year since Scala 2.13 broke this code. Multiple tickets that sound related to this issue had been opened; some were closed. This ticket was opened almost two months ago and did not see any activity since.

I would really like to know: was this kind of code never legal, and family polymorphism encoding that I use only compiled (and run) prior to Scala 2.13 by mistake, or is there a bug in Scala 2.13.0, 2.13.1 and 2.13.2 compiler and Dotty compiler up to 0.26? If it is the former, I guess I need to start looking for alternatives; if it is the later, I'd like to have some idea about the timeline of the fix :)

Since Scala type system is on solid foundation for the last 6 years, it shouldn't take somebody who is familiar with that foundation long to make the determination here. Do you think this can be arranged?

Thanks!

@dubinsky
Copy link
Author

dubinsky commented Jul 5, 2020

@SethTisue ?

@dubinsky
Copy link
Author

@odersky sorry to bother you directly, but I do not see any other way to find out if the 10-lines code snippet above is legal Scala...

@odersky
Copy link

odersky commented Jul 13, 2020

With illegal cyclic references the truth is basically what the compiler says. The compiler has an enormous amount of code and intelligence devoted to not getting it into infinite loops and stack-overflows, at least for the most part. The only argument would be to point out that a cyclic reference is not necessary since there is a reasonable way to avoid it.

But the code given won't be legal Scala 3 anyway because of the S#Point construction (see the "type projections" part of the dotty reference).

@dubinsky
Copy link
Author

Thank you for a speedy reply!

With illegal cyclic references the truth is basically what the compiler says.

So, what is legal with Scala 2.12 compiler is illegal with Scala 2.13 compiler, and both are correct?
No possibility of a compiler bug, numerous issues alleging such bugs in the cycle-detection notwithstanding?

cyclic reference is not necessary since there is a reasonable way to avoid it

Any pointers to the way to avoid such cyclic references?

the code given won't be legal Scala 3 anyway because of the S#Point construction

That's what I expected, but Dotty 0.26 compiler did not complain about general type projection...

Do you know of any examples, discussions or papers on family polymorphism encoding in Scala such that it:

  • allows family members to reside in separate files, with no enclosing traits (or cakes);
  • works for Scala 3 (no abstract type projections);
  • works for Scala 2.13 (no Scala 3-specific features required)?

Thanks!

@smarter
Copy link
Member

smarter commented Jul 13, 2020

That's what I expected, but Dotty 0.26 compiler did not complain about general type projection...

Yeah it's not disabled yet, it requires using -source 3.1 currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants