aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-28 18:33:48 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-28 21:00:45 +0100
commit4dadbda073422eba3745866737f438aa772169df (patch)
treec43c3a5bdf33f7b573c9784510f252748a578098 /src/dotty/tools/dotc/core/Types.scala
parenta9fe1a9cd4514406b54d03ef51740373429dfe05 (diff)
downloaddotty-4dadbda073422eba3745866737f438aa772169df.tar.gz
dotty-4dadbda073422eba3745866737f438aa772169df.tar.bz2
dotty-4dadbda073422eba3745866737f438aa772169df.zip
Refactorings in TypeComparers and elsewhere
Broke out common functionality in two new methods: widenExpr, and commonVariance.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 1f1560603..bfe19c859 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -542,6 +542,13 @@ object Types {
case _ => this
}
+ /** Widen from ExprType type to its result type.
+ */
+ final def widenExpr: Type = this match {
+ case tp: ExprType => tp.resultType
+ case _ => this
+ }
+
/** Widen type if it is unstable (i.e. an EpxprType, or Termref to unstable symbol */
final def widenIfUnstable(implicit ctx: Context): Type = this match {
case tp: ExprType => tp.resultType.widenIfUnstable
@@ -1788,10 +1795,10 @@ object Types {
def contains(tp: Type)(implicit ctx: Context) = lo <:< tp && tp <:< hi
def & (that: TypeBounds)(implicit ctx: Context): TypeBounds =
- derivedTypeBounds(this.lo | that.lo, this.hi & that.hi, (this.variance + that.variance) / 2)
+ derivedTypeBounds(this.lo | that.lo, this.hi & that.hi, this commonVariance that)
def | (that: TypeBounds)(implicit ctx: Context): TypeBounds =
- derivedTypeBounds(this.lo & that.lo, this.hi | that.hi, (this.variance + that.variance) / 2)
+ derivedTypeBounds(this.lo & that.lo, this.hi | that.hi, this commonVariance that)
override def & (that: Type)(implicit ctx: Context) = that match {
case that: TypeBounds => this & that
@@ -1803,6 +1810,9 @@ object Types {
case _ => super.| (that)
}
+ /** If this type and that type have the same variance, this variance, otherwise 0 */
+ final def commonVariance(that: TypeBounds): Int = (this.variance + that.variance) / 2
+
/** Given a the typebounds L..H of higher-kinded abstract type
*
* type T[boundSyms] >: L <: H