Skip to content

Commit a536955

Browse files
committed
Turn some calls to underlying into superType.
1 parent f58c158 commit a536955

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,8 @@ class Definitions {
15651565
def tupleTypes(tp: Type, bound: Int = Int.MaxValue)(using Context): Option[List[Type]] = {
15661566
@tailrec def rec(tp: Type, acc: List[Type], bound: Int): Option[List[Type]] = tp.normalized.dealias match {
15671567
case _ if bound < 0 => Some(acc.reverse)
1568-
case tp: AppliedType if defn.PairClass == tp.classSymbol => rec(tp.args(1), tp.args.head :: acc, bound - 1)
1569-
case tp: AppliedType if defn.isTupleClass(tp.tycon.classSymbol) => Some(acc.reverse ::: tp.args)
1568+
case tp: AppliedType if PairClass == tp.classSymbol => rec(tp.args(1), tp.args.head :: acc, bound - 1)
1569+
case tp: AppliedType if isTupleNType(tp) => Some(acc.reverse ::: tp.args)
15701570
case tp: TermRef if tp.symbol == defn.EmptyTupleModule => Some(acc.reverse)
15711571
case _ => None
15721572
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ object Types {
255255
case tp: NamedType => tp.info.isTightPrefix(sym)
256256
case tp: ClassInfo => tp.cls eq sym
257257
case tp: Types.ThisType => tp.cls eq sym
258-
case tp: TypeProxy => tp.underlying.isTightPrefix(sym)
258+
case tp: TypeProxy => tp.superType.isTightPrefix(sym)
259259
case tp: AndType => tp.tp1.isTightPrefix(sym) && tp.tp2.isTightPrefix(sym)
260260
case tp: OrType => tp.tp1.isTightPrefix(sym) || tp.tp2.isTightPrefix(sym)
261261
case _ => false
@@ -331,7 +331,7 @@ object Types {
331331
val sym = tp.symbol
332332
if (sym.isClass) sym == defn.AnyKindClass else loop(tp.translucentSuperType)
333333
case tp: TypeProxy =>
334-
loop(tp.underlying)
334+
loop(tp.underlying) // underlying OK here since an AnyKinded type cannot be a type argument of another type
335335
case _ =>
336336
false
337337
}
@@ -342,6 +342,7 @@ object Types {
342342
final def isNotNull(using Context): Boolean = this match {
343343
case tp: ConstantType => tp.value.value != null
344344
case tp: ClassInfo => !tp.cls.isNullableClass && tp.cls != defn.NothingClass
345+
case tp: AppliedType => tp.superType.isNotNull
345346
case tp: TypeBounds => tp.lo.isNotNull
346347
case tp: TypeProxy => tp.underlying.isNotNull
347348
case AndType(tp1, tp2) => tp1.isNotNull || tp2.isNotNull
@@ -501,7 +502,7 @@ object Types {
501502
val sym = tp.symbol
502503
if (sym.isClass) sym else tp.superType.classSymbol
503504
case tp: TypeProxy =>
504-
tp.underlying.classSymbol
505+
tp.superType.classSymbol
505506
case tp: ClassInfo =>
506507
tp.cls
507508
case AndType(l, r) =>
@@ -535,7 +536,7 @@ object Types {
535536
val sym = tp.symbol
536537
if (include(sym)) sym :: Nil else tp.superType.parentSymbols(include)
537538
case tp: TypeProxy =>
538-
tp.underlying.parentSymbols(include)
539+
tp.superType.parentSymbols(include)
539540
case tp: ClassInfo =>
540541
tp.cls :: Nil
541542
case AndType(l, r) =>
@@ -557,7 +558,7 @@ object Types {
557558
val sym = tp.symbol
558559
sym == cls || !sym.isClass && tp.superType.hasClassSymbol(cls)
559560
case tp: TypeProxy =>
560-
tp.underlying.hasClassSymbol(cls)
561+
tp.superType.hasClassSymbol(cls)
561562
case tp: ClassInfo =>
562563
tp.cls == cls
563564
case AndType(l, r) =>
@@ -571,12 +572,14 @@ object Types {
571572
* bounds of type variables in the constraint.
572573
*/
573574
def isMatchableBound(using Context): Boolean = dealias match
574-
case tp: TypeRef => tp.symbol == defn.MatchableClass
575+
case tp: TypeRef =>
576+
val sym = tp.symbol
577+
sym == defn.MatchableClass || !sym.isClass && tp.superType.isMatchableBound
575578
case tp: TypeParamRef =>
576579
ctx.typerState.constraint.entry(tp) match
577580
case bounds: TypeBounds => bounds.hi.isMatchableBound
578581
case _ => false
579-
case tp: TypeProxy => tp.underlying.isMatchableBound
582+
case tp: TypeProxy => tp.superType.isMatchableBound
580583
case tp: AndType => tp.tp1.isMatchableBound || tp.tp2.isMatchableBound
581584
case tp: OrType => tp.tp1.isMatchableBound && tp.tp2.isMatchableBound
582585
case _ => false

compiler/src/dotty/tools/dotc/transform/TypeUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object TypeUtils {
6363
val arity2 = self.tp2.tupleArity
6464
if arity1 == arity2 then arity1 else -1
6565
case _ =>
66-
if defn.isTupleClass(self.classSymbol) then self.dealias.argInfos.length
66+
if defn.isTupleNType(self) then self.dealias.argInfos.length
6767
else -1
6868
}
6969

@@ -80,7 +80,7 @@ object TypeUtils {
8080
case OrType(tp1, tp2) =>
8181
None // We can't combine the type of two tuples
8282
case _ =>
83-
if defn.isTupleClass(self.classSymbol) then Some(self.dealias.argInfos)
83+
if defn.isTupleClass(self.typeSymbol) then Some(self.dealias.argInfos)
8484
else None
8585
}
8686

0 commit comments

Comments
 (0)