From 608fbca82816c6b43def0b38de5f93133954e8ae Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 20 Jan 2014 14:50:51 +0100 Subject: For a typeRef, prefer info.isAlias over symbol.isAliasType Reason: This works even for typeRefs with joint-ref denotations, even if the symbol does not exist. The only reason to use symbol.isAliasType is if info.isAlias can produce a cycle. --- src/dotty/tools/dotc/Main.scala | 4 ++-- src/dotty/tools/dotc/core/TypeApplications.scala | 2 +- src/dotty/tools/dotc/core/TypeOps.scala | 2 +- src/dotty/tools/dotc/core/Types.scala | 9 ++++++++- src/dotty/tools/dotc/typer/Applications.scala | 2 +- src/dotty/tools/dotc/typer/Implicits.scala | 2 +- src/dotty/tools/dotc/typer/Inferencing.scala | 13 +++---------- 7 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala index 7c132ef04..0222924da 100644 --- a/src/dotty/tools/dotc/Main.scala +++ b/src/dotty/tools/dotc/Main.scala @@ -13,10 +13,10 @@ 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. Look for #dealias * - Don't open package objects from class files if they are present in source + * - Revise the way classes are inherited - when not followed by [...] or (...), + * assume the unparameterized type and forward type parameters as we do now for the synthetic head class. */ - object Main extends Driver { def resident(compiler: Compiler): Reporter = unsupported("resident") /*loop { line => val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError)) diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index d4db07ef2..8e068f5d3 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -33,7 +33,7 @@ class TypeApplications(val self: Type) extends AnyVal { case tp: TypeRef => val tsym = tp.typeSymbol if (tsym.isClass) tsym.typeParams - else if (tsym.isAliasType) tp.underlying.typeParams + else if (tsym.info.isAlias) tp.underlying.typeParams else tp.info.bounds.hi match { case AndType(hkBound, other) if defn.hkTraits contains hkBound.typeSymbol => hkBound.typeSymbol.typeParams diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index f3ddf3cc1..e2352d89e 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -165,7 +165,7 @@ trait TypeOps { this: Context => formals = formals.updated(name, tp1.typeParamNamed(name)) normalizeToRef(tp1) case tp: TypeRef => - if (tp.symbol.isAliasType) normalizeToRef(tp.info.bounds.hi) + if (tp.symbol.info.isAlias) normalizeToRef(tp.info.bounds.hi) else tp case ErrorType => defn.AnyClass.typeRef diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 9d6faef75..b628d9c50 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -173,9 +173,16 @@ object Types { final def occursIn(that: Type)(implicit ctx: Context): Boolean = that existsPart (this == _) + /** Is this a type of a repeated parameter? */ def isRepeatedParam(implicit ctx: Context): Boolean = defn.RepeatedParamClasses contains typeSymbol + /** Is this an alias TypeBounds? */ + def isAlias: Boolean = this match { + case TypeBounds(lo, hi) => lo eq hi + case _ => false + } + // ----- Higher-order combinators ----------------------------------- /** Returns true if there is a part of this type that satisfies predicate `p`. @@ -672,7 +679,7 @@ object Types { */ final def normalizedPrefix(implicit ctx: Context): Type = this match { case tp: NamedType => - if (tp.symbol.isAliasType) tp.info.normalizedPrefix else tp.prefix + if (tp.symbol.info.isAlias) tp.info.normalizedPrefix else tp.prefix case tp: ClassInfo => tp.prefix case tp: TypeProxy => diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 1ee34e4be..0969562da 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -544,7 +544,7 @@ trait Applications extends Compatibility { self: Typer => case tree: untpd.RefTree => val ttree = typedType(tree.withName(tree.name.toTypeName)) ttree.tpe match { - case alias: TypeRef if alias.symbol.isAliasType => + case alias: TypeRef if alias.info.isAlias => companionRef(alias) match { case companion: TermRef => return untpd.ref(companion) withPos tree.pos case _ => diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index 9cc472ba4..10ba90055 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -485,7 +485,7 @@ class SearchHistory(val searchDepth: Int, val seen: Map[ClassSymbol, Int]) { def apply(n: Int, tp: Type): Int = tp match { case tp: RefinedType => foldOver(n + 1, tp) - case tp: TypeRef if tp.symbol.isAliasType => + case tp: TypeRef if tp.info.isAlias => apply(n, tp.info.bounds.hi) case _ => foldOver(n, tp) diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index fba2201bf..6e522b831 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -305,16 +305,9 @@ object Inferencing { inst } private var toMaximize: Boolean = false - def apply(x: Boolean, tp: Type): Boolean = tp match { + def apply(x: Boolean, tp: Type): Boolean = tp.dealias 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 { @@ -324,9 +317,9 @@ object Inferencing { isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true))) if (minimize) instantiate(tvar, fromBelow = true) else toMaximize = true - foldOver(x, tp) + foldOver(x, tvar) } - case _ => + case tp => foldOver(x, tp) } -- cgit v1.2.3