aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-14 18:06:48 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-14 19:52:22 +0200
commit82fc27f0c2c800de786b54110cfd8627b043fe6d (patch)
tree92bff1bc2f6869495e46fd77a1220153c25b46ac /src/dotty/tools/dotc/core/Types.scala
parent18b30803952cee83580eab28068bc773fdce780e (diff)
downloaddotty-82fc27f0c2c800de786b54110cfd8627b043fe6d.tar.gz
dotty-82fc27f0c2c800de786b54110cfd8627b043fe6d.tar.bz2
dotty-82fc27f0c2c800de786b54110cfd8627b043fe6d.zip
Fix bounds checking of hk applied typed
Previous logic could only handle classes as constructors. Also, address other reviewers comments.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala45
1 files changed, 14 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 1bfe9cbd1..fa402f9fc 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -517,7 +517,7 @@ object Types {
def goApply(tp: HKApply) = tp.tycon match {
case tl: TypeLambda =>
go(tl.resType).mapInfo(info =>
- tl.derivedTypeLambda(tl.paramNames, tl.paramBounds, info).appliedTo(tp.args))
+ tl.derivedLambdaAbstraction(tl.paramNames, tl.paramBounds, info).appliedTo(tp.args))
case _ =>
go(tp.superType)
}
@@ -879,12 +879,6 @@ object Types {
case _ => this
}
- /** If this is a TypeAlias type, its alias, otherwise this type itself */
- final def followTypeAlias(implicit ctx: Context): Type = this match {
- case TypeAlias(alias) => alias
- case _ => this
- }
-
/** If this is a (possibly aliased, annotated, and/or parameterized) reference to
* a class, the class type ref, otherwise NoType.
* @param refinementOK If `true` we also skip non-parameter refinements.
@@ -1923,13 +1917,9 @@ object Types {
}
object TypeRef {
- def checkProjection(prefix: Type, name: TypeName)(implicit ctx: Context) = ()
-
/** Create type ref with given prefix and name */
- def apply(prefix: Type, name: TypeName)(implicit ctx: Context): TypeRef = {
- if (Config.checkProjections) checkProjection(prefix, name)
+ def apply(prefix: Type, name: TypeName)(implicit ctx: Context): TypeRef =
ctx.uniqueNamedTypes.enterIfNew(prefix, name).asInstanceOf[TypeRef]
- }
/** Create type ref to given symbol */
def apply(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
@@ -1938,10 +1928,8 @@ object Types {
/** Create a non-member type ref (which cannot be reloaded using `member`),
* with given prefix, name, and symbol.
*/
- def withFixedSym(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRef = {
- if (Config.checkProjections) checkProjection(prefix, name)
+ def withFixedSym(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
unique(new TypeRefWithFixedSym(prefix, name, sym))
- }
/** Create a type ref referring to given symbol with given name.
* This is very similar to TypeRef(Type, Symbol),
@@ -2057,9 +2045,7 @@ object Types {
private def badInst =
throw new AssertionError(s"bad instantiation: $this")
- def checkInst(implicit ctx: Context): this.type = {
- this
- }
+ def checkInst(implicit ctx: Context): this.type = this // debug hook
def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(implicit ctx: Context): Type =
if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this
@@ -2139,7 +2125,7 @@ object Types {
override def computeHash = doHash(parent)
override def toString = s"RecType($parent | $hashCode)"
- private def checkInst(implicit ctx: Context): this.type = this
+ private def checkInst(implicit ctx: Context): this.type = this // debug hook
}
object RecType {
@@ -2550,8 +2536,8 @@ object Types {
case _ => false
}
- def derivedPolyType(paramNames: List[TypeName], paramBounds: List[TypeBounds], resType: Type)(implicit ctx: Context) =
- derivedGenericType(paramNames, paramBounds, resType)
+ def derivedPolyType(paramNames: List[TypeName], paramBounds: List[TypeBounds], resType: Type)(implicit ctx: Context): PolyType =
+ derivedGenericType(paramNames, paramBounds, resType).asInstanceOf[PolyType]
def duplicate(paramNames: List[TypeName] = this.paramNames, paramBounds: List[TypeBounds] = this.paramBounds, resType: Type)(implicit ctx: Context): PolyType =
PolyType(paramNames)(
@@ -2591,7 +2577,7 @@ object Types {
lazy val typeParams: List[LambdaParam] =
paramNames.indices.toList.map(new LambdaParam(this, _))
- def derivedTypeLambda(paramNames: List[TypeName] = paramNames, paramBounds: List[TypeBounds] = paramBounds, resType: Type)(implicit ctx: Context): Type =
+ def derivedLambdaAbstraction(paramNames: List[TypeName], paramBounds: List[TypeBounds], resType: Type)(implicit ctx: Context): Type =
resType match {
case resType @ TypeAlias(alias) =>
resType.derivedTypeAlias(duplicate(paramNames, paramBounds, alias))
@@ -2600,9 +2586,12 @@ object Types {
if (lo.isRef(defn.NothingClass)) lo else duplicate(paramNames, paramBounds, lo),
duplicate(paramNames, paramBounds, hi))
case _ =>
- derivedGenericType(paramNames, paramBounds, resType)
+ derivedTypeLambda(paramNames, paramBounds, resType)
}
+ def derivedTypeLambda(paramNames: List[TypeName] = paramNames, paramBounds: List[TypeBounds] = paramBounds, resType: Type)(implicit ctx: Context): TypeLambda =
+ derivedGenericType(paramNames, paramBounds, resType).asInstanceOf[TypeLambda]
+
def duplicate(paramNames: List[TypeName] = this.paramNames, paramBounds: List[TypeBounds] = this.paramBounds, resType: Type)(implicit ctx: Context): TypeLambda =
TypeLambda(paramNames, variances)(
x => paramBounds mapConserve (_.subst(this, x).bounds),
@@ -2664,6 +2653,7 @@ object Types {
cachedSuper
}
+ /* (Not needed yet) */
def lowerBound(implicit ctx: Context) = tycon.stripTypeVar match {
case tycon: TypeRef =>
tycon.info match {
@@ -2676,13 +2666,6 @@ object Types {
NoType
}
-/*
- def lowerBound(implicit ctx: Context): Type = tycon.stripTypeVar match {
- case tp: TypeRef =>
- val lb = tp.info.bounds.lo.typeParams.length == args.lengt
- case _ => defn.NothingType
- }
-*/
def typeParams(implicit ctx: Context): List[TypeParamInfo] = {
val tparams = tycon.typeParams
if (tparams.isEmpty) TypeLambda.any(args.length).typeParams else tparams
@@ -2705,7 +2688,7 @@ object Types {
case _ =>
assert(false, s"illegal type constructor in $this")
}
- check(tycon)
+ if (Config.checkHKApplications) check(tycon)
this
}
}