Skip to content

Commit 608fbca

Browse files
committed
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.
1 parent 0a8c17e commit 608fbca

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

src/dotty/tools/dotc/Main.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import reporting.Reporter
1313
* - make use of AndOrType
1414
* - review isSubType
1515
* - have a second look at normalization (leave at method types if pt is method type?)
16-
* - Check usages of isAliasType and replace where possible by looking at the info. Look for #dealias
1716
* - Don't open package objects from class files if they are present in source
17+
* - Revise the way classes are inherited - when not followed by [...] or (...),
18+
* assume the unparameterized type and forward type parameters as we do now for the synthetic head class.
1819
*/
19-
2020
object Main extends Driver {
2121
def resident(compiler: Compiler): Reporter = unsupported("resident") /*loop { line =>
2222
val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError))

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TypeApplications(val self: Type) extends AnyVal {
3333
case tp: TypeRef =>
3434
val tsym = tp.typeSymbol
3535
if (tsym.isClass) tsym.typeParams
36-
else if (tsym.isAliasType) tp.underlying.typeParams
36+
else if (tsym.info.isAlias) tp.underlying.typeParams
3737
else tp.info.bounds.hi match {
3838
case AndType(hkBound, other) if defn.hkTraits contains hkBound.typeSymbol =>
3939
hkBound.typeSymbol.typeParams

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ trait TypeOps { this: Context =>
165165
formals = formals.updated(name, tp1.typeParamNamed(name))
166166
normalizeToRef(tp1)
167167
case tp: TypeRef =>
168-
if (tp.symbol.isAliasType) normalizeToRef(tp.info.bounds.hi)
168+
if (tp.symbol.info.isAlias) normalizeToRef(tp.info.bounds.hi)
169169
else tp
170170
case ErrorType =>
171171
defn.AnyClass.typeRef

src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,16 @@ object Types {
173173
final def occursIn(that: Type)(implicit ctx: Context): Boolean =
174174
that existsPart (this == _)
175175

176+
/** Is this a type of a repeated parameter? */
176177
def isRepeatedParam(implicit ctx: Context): Boolean =
177178
defn.RepeatedParamClasses contains typeSymbol
178179

180+
/** Is this an alias TypeBounds? */
181+
def isAlias: Boolean = this match {
182+
case TypeBounds(lo, hi) => lo eq hi
183+
case _ => false
184+
}
185+
179186
// ----- Higher-order combinators -----------------------------------
180187

181188
/** Returns true if there is a part of this type that satisfies predicate `p`.
@@ -672,7 +679,7 @@ object Types {
672679
*/
673680
final def normalizedPrefix(implicit ctx: Context): Type = this match {
674681
case tp: NamedType =>
675-
if (tp.symbol.isAliasType) tp.info.normalizedPrefix else tp.prefix
682+
if (tp.symbol.info.isAlias) tp.info.normalizedPrefix else tp.prefix
676683
case tp: ClassInfo =>
677684
tp.prefix
678685
case tp: TypeProxy =>

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ trait Applications extends Compatibility { self: Typer =>
544544
case tree: untpd.RefTree =>
545545
val ttree = typedType(tree.withName(tree.name.toTypeName))
546546
ttree.tpe match {
547-
case alias: TypeRef if alias.symbol.isAliasType =>
547+
case alias: TypeRef if alias.info.isAlias =>
548548
companionRef(alias) match {
549549
case companion: TermRef => return untpd.ref(companion) withPos tree.pos
550550
case _ =>

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ class SearchHistory(val searchDepth: Int, val seen: Map[ClassSymbol, Int]) {
485485
def apply(n: Int, tp: Type): Int = tp match {
486486
case tp: RefinedType =>
487487
foldOver(n + 1, tp)
488-
case tp: TypeRef if tp.symbol.isAliasType =>
488+
case tp: TypeRef if tp.info.isAlias =>
489489
apply(n, tp.info.bounds.hi)
490490
case _ =>
491491
foldOver(n, tp)

src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,9 @@ object Inferencing {
305305
inst
306306
}
307307
private var toMaximize: Boolean = false
308-
def apply(x: Boolean, tp: Type): Boolean = tp match {
308+
def apply(x: Boolean, tp: Type): Boolean = tp.dealias match {
309309
case _: WildcardType =>
310310
false
311-
case tp: TypeRef =>
312-
// todo: factor out? same logic is also used in avoid.
313-
// and interestingly it does not work with #dealias
314-
tp.info match {
315-
case TypeAlias(ref) => apply(x, ref)
316-
case _ => foldOver(x, tp)
317-
}
318311
case tvar: TypeVar if !tvar.isInstantiated =>
319312
if (force == ForceDegree.none) false
320313
else {
@@ -324,9 +317,9 @@ object Inferencing {
324317
isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true)))
325318
if (minimize) instantiate(tvar, fromBelow = true)
326319
else toMaximize = true
327-
foldOver(x, tp)
320+
foldOver(x, tvar)
328321
}
329-
case _ =>
322+
case tp =>
330323
foldOver(x, tp)
331324
}
332325

0 commit comments

Comments
 (0)