aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeApplications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-08 12:24:34 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-20 13:02:40 +0100
commit88c4a6cddefb6bf3e7d1ac3c61358cc06abd8bd4 (patch)
treeb3438b800980b8684646d62591a569dc55094cdf /src/dotty/tools/dotc/core/TypeApplications.scala
parent7a04b119c9744262bd46c1795b811f56df9516a6 (diff)
downloaddotty-88c4a6cddefb6bf3e7d1ac3c61358cc06abd8bd4.tar.gz
dotty-88c4a6cddefb6bf3e7d1ac3c61358cc06abd8bd4.tar.bz2
dotty-88c4a6cddefb6bf3e7d1ac3c61358cc06abd8bd4.zip
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#|`.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeApplications.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index b4c30d902..0abd28a71 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -170,17 +170,20 @@ class TypeApplications(val self: Type) extends AnyVal {
/** The type arguments of this type's base type instance wrt.`base`.
* Existential types in arguments are disallowed.
*/
- final def baseArgTypes(base: Symbol)(implicit ctx: Context): List[Type] = baseArgInfos(base) mapConserve noBounds
+ final def baseArgTypes(base: Symbol)(implicit ctx: Context): List[Type] =
+ baseArgInfos(base) mapConserve noBounds
/** The type arguments of this type's base type instance wrt.`base`.
* Existential types in arguments are approximanted by their lower bound.
*/
- final def baseArgTypesLo(base: Symbol)(implicit ctx: Context): List[Type] = baseArgInfos(base) mapConserve boundsToLo
+ final def baseArgTypesLo(base: Symbol)(implicit ctx: Context): List[Type] =
+ baseArgInfos(base) mapConserve boundsToLo
/** The type arguments of this type's base type instance wrt.`base`.
* Existential types in arguments are approximanted by their upper bound.
*/
- final def baseArgTypesHi(base: Symbol)(implicit ctx: Context): List[Type] = baseArgInfos(base) mapConserve boundsToHi
+ final def baseArgTypesHi(base: Symbol)(implicit ctx: Context): List[Type] =
+ baseArgInfos(base) mapConserve boundsToHi
/** The first type argument of the base type instance wrt `base` of this type */
final def firstBaseArgInfo(base: Symbol)(implicit ctx: Context): Type = base.typeParams match {
@@ -193,8 +196,11 @@ class TypeApplications(val self: Type) extends AnyVal {
/** The base type including all type arguments of this type.
* Existential types in arguments are returned as TypeBounds instances.
*/
- final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type =
- self.baseTypeRef(base).appliedTo(baseArgInfos(base))
+ final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = self.dealias match {
+ case AndType(tp1, tp2) => tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base)
+ case OrType(tp1, tp2) => tp1.baseTypeWithArgs(base) | tp2.baseTypeWithArgs(base)
+ case _ => self.baseTypeRef(base).appliedTo(baseArgInfos(base))
+ }
/** Translate a type of the form From[T] to To[T], keep other types as they are.
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
@@ -205,7 +211,7 @@ class TypeApplications(val self: Type) extends AnyVal {
else self
/** If this is an encoding of a (partially) applied type, return its arguments,
- * otherwise return Nil.
+ * otherwise return Nil.
* Existential types in arguments are returned as TypeBounds instances.
*/
final def argInfos(implicit ctx: Context): List[Type] = {