-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Topic/language features #75
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
Conversation
Add a method "featureEnabled" that checks whether a feature is enabled. Features can be enabled by imports or by command-line options. The Scala 2.10 way of enabling features by implicits got dropped, because the use of the feature mechanism is now different. Previously, features imposed restrictions on what used to work. So it was important to offer way to avoid the restrictions it that was as smooth as possible, and implicits fit the bill. Furthermore, features did not change the way things were compiled, so it was OK to test them only once all types were compiled. Now, features are essentially switches that change compile time behavior. keepUnions and noAutoTupling, if on, will modify the way type inference works. So we need to interprete a switch on the spot, and doing an implicit search to determine a switch value is too dangerous in what concerns causing cyclic references. At the same time, because we are dealing with new functionality, there is less of a concern for being able to set or reset features for large pieces of code with some implicit. You could argue that's not even desirable, and that an explicit import or command line option is preferable.
Auto-tupling should satisfy the following spec. 1. An application `f(args)` where `f` is a non-overloaded method which has a single, non-repeated parameter as its first parameter list and where args consists of two or more arguments is expanded to `f((args))`. 2. A constructor pattern `C(args)` where `C.unapply` is a non-overloaded method which has a single, non-repeated parameter as its first parameter list and where args consists of two or more arguments is expanded to `C((args))`. Auto-tupling can be disabled by language feature "noAutoTupling".
Eliminated all "Dotty deviations" which were due to lack of auto-tupling.
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.
Removed annotations from the dotty codebase that were necessary because the inferred union types caused inference errors later on.
Review by @srrd @DarkDimius |
@@ -890,6 +890,16 @@ class TypeComparer(initctx: Context) extends DotClass { | |||
|
|||
/** Try to distribute `&` inside type, detect and handle conflicts */ | |||
private def distributeAnd(tp1: Type, tp2: Type): Type = tp1 match { | |||
case tp1: RefinedType => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was documentation removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which documentation?
I something was removed it was probably not intentional, but because I went through a nightmare of rebasings and merges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM |
Otherwise LGTM |
And added a neg test that verifies that import language.noAutoTupling indeed disables auto-tupling. Also added back comment that @DarkDimius found missing.
Backport "Fix scala#20271: Bring for comprehension spec up to date." to 3.3 LTS
Three parts: