Skip to content

Try/collapsed lubs #52

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

Closed
wants to merge 4 commits into from
Closed

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 8, 2014

See comment on third commit for motivation.

odersky added 3 commits March 8, 2014 19:12
Introduce new cases for AndTypes and OrTypes in methods `derivesFrom`, `baseClasses`, and `baseTypeWithArgs`.
These cases are ultimately needed so that `baseTypeWithArgs` makes sense for union and intersection types.

Also, fixed embarrassing typo in method `TypeBounds#|`.
Use the equality (where ~ is any form of refinement)

  T1 { x ~ R1 } & T2 { x ~ R2 }  ==  T1 & T2 { x ~ R1 & R2 }

We already did the same thing when distributing via "&".
Appromiximate union types by intersections of their common base classes. Controlled by option -Xkeep-unions.
If option is set, no approximation is done.

Motivations for approximating: There are two. First, union types are departure from Scala 2. From time to
time they lead to failure of inference. One example experiences in Dotty was in a foldLeft, where the accumulator
type was inferred to be Tree before and was now a union of two tree specific kinds. Tree was the correct type, whereas
the union type was too specific. These failures are not common (in the Dotty codebase there were 3, I believe), but
they cause considerable difficulty to diagnose. So it seems safer to have a compatibility mode with Scala 2.
The second motivation is that union types can become large and unwieldy. A function like TreeCopier has a result
type consisting of ~ 40 alternatives, where the alternative type would be just Tree.

Once we gain more experience with union types, we might consider flipping the option, and making union types the
default. But for now it is safer this way, I believe.
@odersky
Copy link
Contributor Author

odersky commented Mar 8, 2014

Reviews by @adriaanm @sjrd

Removed annotations from the dotty codebase that were necessary because the inferred union types
caused inference errors later on.
@odersky
Copy link
Contributor Author

odersky commented Mar 16, 2014

Subsumed by #75

@odersky odersky closed this Mar 16, 2014
@odersky odersky deleted the try/collapsed-lubs branch March 16, 2014 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant