-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Compilation never stops with an upper bounded type param using a union type with 3 types #14870
Comments
Hard to say what is at the root of this without a full analysis of squants. We need a minimization here to be able to act on this. |
Minimization: abstract class Quantity[A <: Quantity[A]]
class Energy extends Quantity[Energy]
class Time extends Quantity[Time]
class Dimensionless extends Quantity[Dimensionless]
class Price[Q <: Quantity[Q] & (Energy | Time | Dimensionless)] |
Thanks for the minimization! I looked at this for a while, but could not see a specific problem that we could fix. It seems to be a combinatorial explosion of recursive subtype tests. My advice would be to not use F-bounded types, and certainly not in conjunction with complicated Over time we should try to make F-bounded types deprecated. They really interact terribly with almost everything else in the language. We need to keep them for Java compat, but maybe we can restrict them to |
Squants defines class Price[Q <: (Energy | Time | Dimensionless)](amount: Double, per: UnitOfMeasure[Q]) Which in an ideal world would compile since Energy, Time, and Dimensionless are all subclasses of It would be interesting to see how to solve problems the f-bounds solve without using them. |
Don't recursively apply joins on the left hand side if it contains an AndType, in order to prevent possible exponential explosions. Fixes scala#14870
I could find the culprit that caused the exponential explosion, and it looks like this case can be fixed, after all. |
Don't recursively apply joins on the left hand side if it contains an AndType, in order to prevent possible exponential explosions. Fixes scala#14870
Compiler version
3.1.1
Minimized code
This code compiles (although it takes a little bit, aka more than usual for so little code)
Changing Price to
Causes the compiler to never stop compiling.
Output
Scastie times out after 30 seconds.
Ran locally for 300 seconds then killed it.
Expectation
With a union type of 2 types it works, but with 3 types it fails. This suggests a explosion of combinations to big to handle in a reasonable time. There must be a limit to this explosion of combinations, however I was expecting it to be much higher: in the tens or even in the hundreds not 3.
The text was updated successfully, but these errors were encountered: