aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-12-10 15:25:33 +0100
committerMartin Odersky <odersky@gmail.com>2014-12-10 18:54:47 +0100
commita5d2dc330b7d148eec809343d6906b438f11e746 (patch)
treeceafb2bb892dd40811e83c2c8c40230d5cf8acf4 /src/dotty/tools/dotc
parentb1b76515a66d94e9552f3ccde02cb4d1bacbc0ec (diff)
downloaddotty-a5d2dc330b7d148eec809343d6906b438f11e746.tar.gz
dotty-a5d2dc330b7d148eec809343d6906b438f11e746.tar.bz2
dotty-a5d2dc330b7d148eec809343d6906b438f11e746.zip
Distinguish calls to create real type bounds from alias type bounds.
So far this affects only the calls, both methods are still the same. But their implementation will be changed next.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala4
-rw-r--r--src/dotty/tools/dotc/core/Types.scala37
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala2
-rw-r--r--src/dotty/tools/dotc/typer/TypeAssigner.scala2
4 files changed, 23 insertions, 22 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 2742d77f2..c3907d34f 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -619,7 +619,7 @@ class TypeComparer(initctx: Context) extends DotClass {
case TypeBounds(lo1, hi1) =>
if ((ctx.mode is Mode.GADTflexible) && (tp1.symbol is GADTFlexType) &&
!isSubTypeWhenFrozen(hi1, tp2))
- trySetType(tp1, TypeBounds(lo1, hi1 & tp2))
+ trySetType(tp1, TypeBounds.real(lo1, hi1 & tp2))
else if (lo1 eq hi1) isSubType(hi1, tp2)
else tryRebase2nd
case _ =>
@@ -638,7 +638,7 @@ class TypeComparer(initctx: Context) extends DotClass {
case TypeBounds(lo2, hi2) =>
if ((ctx.mode is Mode.GADTflexible) && (tp2.symbol is GADTFlexType) &&
!isSubTypeWhenFrozen(tp1, lo2))
- trySetType(tp2, TypeBounds(lo2 | tp1, hi2))
+ trySetType(tp2, TypeBounds.real(lo2 | tp1, hi2))
else
((frozenConstraint || !isCappable(tp1)) && isSubType(tp1, lo2)
|| tryRebase3rd)
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 00c6af676..17b0d6f38 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -2398,16 +2398,18 @@ object Types {
override def underlying(implicit ctx: Context): Type = hi
- def derivedTypeBounds(lo: Type, hi: Type, variance: Int = this.variance)(implicit ctx: Context) =
- if ((lo eq this.lo) && (hi eq this.hi) && (variance == this.variance)) this
- else TypeBounds(lo, hi, variance)
+ /** The non-variant type bounds or alias type with given bounds */
+ def derivedTypeBounds(lo: Type, hi: Type)(implicit ctx: Context) =
+ if ((lo eq this.lo) && (hi eq this.hi) && (variance == 0)) this
+ else TypeBounds.orAlias(lo, hi)
/** If this is an alias, a derived alias with the new variance,
* Otherwise the type itself.
*/
- def withVariance(variance: Int)(implicit ctx: Context) =
- if (lo ne hi) this
- else derivedTypeBounds(lo, hi, variance)
+ def withVariance(variance: Int)(implicit ctx: Context) = this match {
+ case tp: TypeAlias => tp.derivedTypeAlias(tp.alias, variance)
+ case _ => this
+ }
def contains(tp: Type)(implicit ctx: Context) = tp match {
case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi
@@ -2421,7 +2423,7 @@ object Types {
if (v > 0) thisAlias.derivedTypeAlias(this.hi & that.hi, v)
else thisAlias.derivedTypeAlias(this.lo | that.lo, v)
}
- else derivedTypeBounds(this.lo | that.lo, this.hi & that.hi, v)
+ else derivedTypeBounds(this.lo | that.lo, this.hi & that.hi)
}
def | (that: TypeBounds)(implicit ctx: Context): TypeBounds = {
@@ -2431,7 +2433,7 @@ object Types {
if (v > 0) thisAlias.derivedTypeAlias(this.hi | that.hi, v)
else thisAlias.derivedTypeAlias(this.lo & that.lo, v)
}
- else derivedTypeBounds(this.lo & that.lo, this.hi | that.hi, v)
+ else derivedTypeBounds(this.lo & that.lo, this.hi | that.hi)
}
override def & (that: Type)(implicit ctx: Context) = that match {
@@ -2456,7 +2458,6 @@ object Types {
override def toString =
if (lo eq hi) s"TypeAlias($lo)" else s"TypeBounds($lo, $hi)"
-
}
class RealTypeBounds(lo: Type, hi: Type) extends TypeBounds(lo, hi) {
@@ -2476,15 +2477,15 @@ object Types {
}
object TypeBounds {
- def apply(lo: Type, hi: Type, variance: Int = 0)(implicit ctx: Context): TypeBounds =
- if (lo eq hi) TypeAlias(lo, variance)
- else unique {
- assert(variance == 0)
- new RealTypeBounds(lo, hi)
- }
- def empty(implicit ctx: Context) = apply(defn.NothingType, defn.AnyType)
- def upper(hi: Type, variance: Int = 0)(implicit ctx: Context) = apply(defn.NothingType, hi, variance)
- def lower(lo: Type, variance: Int = 0)(implicit ctx: Context) = apply(lo, defn.AnyType, variance)
+ def real(lo: Type, hi: Type)(implicit ctx: Context): TypeBounds =
+ if (lo eq hi) TypeAlias(lo, 0)
+ else unique(new RealTypeBounds(lo, hi))
+ def orAlias(lo: Type, hi: Type)(implicit ctx: Context): TypeBounds =
+ if (lo eq hi) TypeAlias(lo, 0)
+ else unique(new RealTypeBounds(lo, hi))
+ def empty(implicit ctx: Context) = real(defn.NothingType, defn.AnyType)
+ def upper(hi: Type)(implicit ctx: Context) = real(defn.NothingType, hi)
+ def lower(lo: Type)(implicit ctx: Context) = real(lo, defn.AnyType)
}
object TypeAlias {
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index 728048700..b6b62c839 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -656,7 +656,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
if (sym == defn.ByNameParamClass2x) ExprType(args.head)
else tycon.appliedTo(args)
case TYPEBOUNDStpe =>
- TypeBounds(readTypeRef(), readTypeRef())
+ TypeBounds.orAlias(readTypeRef(), readTypeRef())
case REFINEDtpe =>
val clazz = readSymbolRef()
val decls = symScope(clazz)
diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala
index 0f1b81be8..3bec3eb7b 100644
--- a/src/dotty/tools/dotc/typer/TypeAssigner.scala
+++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala
@@ -355,7 +355,7 @@ trait TypeAssigner {
tree.withType(ExprType(result.tpe))
def assignType(tree: untpd.TypeBoundsTree, lo: Tree, hi: Tree)(implicit ctx: Context) =
- tree.withType(TypeBounds(lo.tpe, hi.tpe))
+ tree.withType(TypeBounds.orAlias(lo.tpe, hi.tpe))
def assignType(tree: untpd.Bind, sym: TermSymbol)(implicit ctx: Context) =
tree.withType(TermRef(NoPrefix, sym))