Skip to content

Commit 5b3d933

Browse files
committed
Turn some calls to underlying into superType.
1 parent d60e5dc commit 5b3d933

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
@@ -500,7 +501,7 @@ object Types {
500501
val sym = tp.symbol
501502
if (sym.isClass) sym else tp.superType.classSymbol
502503
case tp: TypeProxy =>
503-
tp.underlying.classSymbol
504+
tp.superType.classSymbol
504505
case tp: ClassInfo =>
505506
tp.cls
506507
case AndType(l, r) =>
@@ -534,7 +535,7 @@ object Types {
534535
val sym = tp.symbol
535536
if (include(sym)) sym :: Nil else tp.superType.parentSymbols(include)
536537
case tp: TypeProxy =>
537-
tp.underlying.parentSymbols(include)
538+
tp.superType.parentSymbols(include)
538539
case tp: ClassInfo =>
539540
tp.cls :: Nil
540541
case AndType(l, r) =>
@@ -556,7 +557,7 @@ object Types {
556557
val sym = tp.symbol
557558
sym == cls || !sym.isClass && tp.superType.hasClassSymbol(cls)
558559
case tp: TypeProxy =>
559-
tp.underlying.hasClassSymbol(cls)
560+
tp.superType.hasClassSymbol(cls)
560561
case tp: ClassInfo =>
561562
tp.cls == cls
562563
case AndType(l, r) =>
@@ -570,12 +571,14 @@ object Types {
570571
* bounds of type variables in the constraint.
571572
*/
572573
def isMatchableBound(using Context): Boolean = dealias match
573-
case tp: TypeRef => tp.symbol == defn.MatchableClass
574+
case tp: TypeRef =>
575+
val sym = tp.symbol
576+
sym == defn.MatchableClass || !sym.isClass && tp.superType.isMatchableBound
574577
case tp: TypeParamRef =>
575578
ctx.typerState.constraint.entry(tp) match
576579
case bounds: TypeBounds => bounds.hi.isMatchableBound
577580
case _ => false
578-
case tp: TypeProxy => tp.underlying.isMatchableBound
581+
case tp: TypeProxy => tp.superType.isMatchableBound
579582
case tp: AndType => tp.tp1.isMatchableBound || tp.tp2.isMatchableBound
580583
case tp: OrType => tp.tp1.isMatchableBound && tp.tp2.isMatchableBound
581584
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)