aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeApplications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-01-10 17:47:55 +0100
committerMartin Odersky <odersky@gmail.com>2015-01-10 17:47:55 +0100
commit97aced07f273a31be69fd771a4e900a8e0cfa43a (patch)
tree5d97ce7b5da0dd2dcfec601d616e530129958faa /src/dotty/tools/dotc/core/TypeApplications.scala
parent5f35b11ceb228e7a803263490f2d8e8a22ee2fe6 (diff)
downloaddotty-97aced07f273a31be69fd771a4e900a8e0cfa43a.tar.gz
dotty-97aced07f273a31be69fd771a4e900a8e0cfa43a.tar.bz2
dotty-97aced07f273a31be69fd771a4e900a8e0cfa43a.zip
Reverting the idea that RefinedThis types take levels.
In the end, this did not buy us anything. What matters is that - we can reliably identify RefinedThis types pointing to a given refinement type. Making sure that the `binder` field of q RefinedThis type in a refinedInfo is always the containing refined type is good enough for that. - we take care to rebind RefinedThis types in isSubType. This was leaky before, is handled now better in the new isSubType. So, in the end, adding a level was a needless complication. Also, as a next step we should be able to identify skolem types and RefinedThis types.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeApplications.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index e71226b68..b29022281 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -373,29 +373,27 @@ class TypeApplications(val self: Type) extends AnyVal {
case _ => firstBaseArgInfo(defn.SeqClass)
}
- def containsRefinedThis(level: Int)(implicit ctx: Context): Boolean = {
- def recur(tp: Type, level: Int): Boolean = tp.stripTypeVar match {
- case RefinedThis(rt, `level`) =>
- true
+ def containsRefinedThis(target: Type)(implicit ctx: Context): Boolean = {
+ def recur(tp: Type): Boolean = tp.stripTypeVar match {
+ case RefinedThis(tp) =>
+ tp eq target
case tp: NamedType =>
tp.info match {
- case TypeAlias(alias) => recur(alias, level)
- case _ => !tp.symbol.isStatic && recur(tp.prefix, level)
+ case TypeAlias(alias) => recur(alias)
+ case _ => !tp.symbol.isStatic && recur(tp.prefix)
}
case tp: RefinedType =>
- recur(tp.refinedInfo, level + 1) ||
- recur(tp.parent, level)
+ recur(tp.refinedInfo) || recur(tp.parent)
case tp: TypeBounds =>
- recur(tp.lo, level) ||
- recur(tp.hi, level)
+ recur(tp.lo) || recur(tp.hi)
case tp: AnnotatedType =>
- recur(tp.underlying, level)
+ recur(tp.underlying)
case tp: AndOrType =>
- recur(tp.tp1, level) || recur(tp.tp2, level)
+ recur(tp.tp1) || recur(tp.tp2)
case _ =>
false
}
- recur(self, level)
+ recur(self)
}
/** Given a type alias
@@ -432,14 +430,16 @@ class TypeApplications(val self: Type) extends AnyVal {
if (bsyms.isEmpty) {
val correspondingNames = correspondingParamName.values.toSet
+ def replacements(rt: RefinedType): List[Type] =
+ for (sym <- boundSyms)
+ yield TypeRef(RefinedThis(rt), correspondingParamName(sym))
+
def rewrite(tp: Type): Type = tp match {
case tp @ RefinedType(parent, name: TypeName) =>
if (correspondingNames contains name) rewrite(parent)
else RefinedType(
- rewrite(parent),
- name,
- new ctx.SubstWithRefinedSelectMap(
- _, boundSyms, boundSyms map correspondingParamName)(tp.refinedInfo))
+ rewrite(parent), name,
+ rt => tp.refinedInfo.subst(boundSyms, replacements(rt)))
case tp =>
tp
}
@@ -474,8 +474,9 @@ class TypeApplications(val self: Type) extends AnyVal {
def expand(tp: Type) = {
val lambda = defn.lambdaTrait(boundSyms.map(_.variance))
val substitutedRHS = (rt: RefinedType) => {
- val argNames = boundSyms.indices.toList.map(tpnme.lambdaArgName)
- new ctx.SubstWithRefinedSelectMap(rt, boundSyms, argNames)(tp).bounds.withVariance(1)
+ val argRefs = boundSyms.indices.toList.map(i =>
+ RefinedThis(rt).select(tpnme.lambdaArgName(i)))
+ tp.subst(boundSyms, argRefs).bounds.withVariance(1)
}
val res = RefinedType(lambda.typeRef, tpnme.Apply, substitutedRHS)
//println(i"lambda abstract $self wrt $boundSyms%, % --> $res")