Dropped: Existential Types
Existential types using forSome have been dropped. The reasons for dropping them were:
-
Existential types violate a type soundness principle on which DOT and Dotty are constructed. That principle says that every prefix (
p, respectvelyS) of a type selectionp.TorS#Tmust either come from a value constructed at runtime or refer to a type that is known to have only good bounds. -
Existential types create many difficult feature interactions with other Scala constructs.
- Existential types largely overlap with path-dependent types, so the gain of having them is relatively minor.
Existential types that can be expressed using only wildcards (but not
forSome) are still supported, but are treated as refined types.
For instance, the type
Map[_ <: AnyRef, Int]
is treated as the type Map, where the first type parameter
is upper-bounded by AnyRef and the second type parameter is an alias
of Int.
When reading classfiles compiled with scalac, Dotty will do a best effort to approximate existential types with its own types. It will issue a warning that a precise emulation is not possible.