aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-19 12:09:23 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-19 12:09:23 +0100
commitd4204733c669ce4b198d9078f84d6617633c6d4f (patch)
tree7235b09b900df0b008c9569454038419d3e99321 /src
parentf11dea6fc2eed56bee3eb1999c3890aae958e897 (diff)
downloaddotty-d4204733c669ce4b198d9078f84d6617633c6d4f.tar.gz
dotty-d4204733c669ce4b198d9078f84d6617633c6d4f.tar.bz2
dotty-d4204733c669ce4b198d9078f84d6617633c6d4f.zip
Refinement of fully-defined accumulator.
It needs to follow type aliases in order not to give false indications what variables are contained in a type.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/Main.scala2
-rw-r--r--src/dotty/tools/dotc/ast/tpd.scala15
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala14
3 files changed, 21 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala
index 22d6d46b8..7c132ef04 100644
--- a/src/dotty/tools/dotc/Main.scala
+++ b/src/dotty/tools/dotc/Main.scala
@@ -13,7 +13,7 @@ import reporting.Reporter
* - make use of AndOrType
* - review isSubType
* - have a second look at normalization (leave at method types if pt is method type?)
- * - Check usages of isAliasType and replace where possible by looking at the info.
+ * - Check usages of isAliasType and replace where possible by looking at the info. Look for #dealias
* - Don't open package objects from class files if they are present in source
*/
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala
index 04fe41b65..fa8bddb26 100644
--- a/src/dotty/tools/dotc/ast/tpd.scala
+++ b/src/dotty/tools/dotc/ast/tpd.scala
@@ -95,15 +95,20 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def avoid(tp: Type, syms: => List[Symbol])(implicit ctx: Context): Type = {
val widenMap = new TypeMap {
lazy val forbidden = syms.toSet
- def toAvoid(sym: Symbol): Boolean = sym.owner.isTerm && (forbidden contains sym)
def toAvoid(tp: Type): Boolean = tp match {
- case tp: TermRef => toAvoid(tp.symbol)
- case _ => false
+ case tp: TermRef =>
+ val sym = tp.symbol
+ sym.exists && (
+ sym.owner.isTerm && (forbidden contains sym)
+ || !(sym.owner is Package) && toAvoid(tp.prefix)
+ )
+ case _ =>
+ false
}
def apply(tp: Type) = tp match {
- case tp: TermRef if toAvoid(tp.symbol) && variance > 0 =>
+ case tp: TermRef if toAvoid(tp) && variance > 0 =>
apply(tp.info)
- case tp @ TypeRef(pre: TermRef, _) if toAvoid(pre.symbol) =>
+ case tp @ TypeRef(pre, _) if toAvoid(pre) =>
tp.info match {
case TypeAlias(ref) => apply(ref)
case _ => mapOver(tp)
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index 6390ed51e..9da57ea53 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -304,10 +304,16 @@ object Inferencing {
inst
}
private var toMaximize: Boolean = false
- def apply(x: Boolean, tp: Type) = x && isOK(tp) && foldOver(x, tp)
- private def isOK(tp: Type): Boolean = tp match {
+ def apply(x: Boolean, tp: Type): Boolean = tp match {
case _: WildcardType =>
false
+ case tp: TypeRef =>
+ // todo: factor out? same logic is also used in avoid.
+ // and interestingly it does not work with #dealias
+ tp.info match {
+ case TypeAlias(ref) => apply(x, ref)
+ case _ => foldOver(x, tp)
+ }
case tvar: TypeVar if !tvar.isInstantiated =>
if (force == ForceDegree.none) false
else {
@@ -317,10 +323,10 @@ object Inferencing {
isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true)))
if (minimize) instantiate(tvar, fromBelow = true)
else toMaximize = true
- true
+ foldOver(x, tp)
}
case _ =>
- true
+ foldOver(x, tp)
}
private class UpperInstantiator(implicit ctx: Context) extends TypeAccumulator[Unit] {