Try/collapsed lubs #52

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
1 participant
@odersky
Contributor

odersky commented Mar 8, 2014

See comment on third commit for motivation.

odersky added some commits Mar 8, 2014

Allow And/OrTypes in baseType operations
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#|`.
Merge refined types when distributing via "|".
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.
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

This comment has been minimized.

Show comment
Hide comment
@odersky

odersky Mar 8, 2014

Contributor

Reviews by @adriaanm @sjrd

Contributor

odersky commented Mar 8, 2014

Reviews by @adriaanm @sjrd

Removed annotations forced by union types
Removed annotations from the dotty codebase that were necessary because the inferred union types
caused inference errors later on.
@odersky

This comment has been minimized.

Show comment
Hide comment
@odersky

odersky Mar 16, 2014

Contributor

Subsumed by #75

Contributor

odersky commented Mar 16, 2014

Subsumed by #75

@odersky odersky closed this Mar 16, 2014

@odersky odersky deleted the odersky:try/collapsed-lubs branch Mar 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment