Skip to content

Commit 4fc5828

Browse files
committed
Make classSymbol also work for SingletonTypes
Analogius to the change for typeSymbol
1 parent 23f0e6d commit 4fc5828

16 files changed

+36
-40
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
416416
private def followOuterLinks(t: Tree)(using Context) = t match {
417417
case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
418418
// after erasure outer paths should be respected
419-
ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.widen.classSymbol)
419+
ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.classSymbol)
420420
case t =>
421421
t
422422
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ trait PatternTypeConstrainer { self: TypeComparer =>
7777

7878
def classesMayBeCompatible: Boolean = {
7979
import Flags._
80-
val patClassSym = pat.widenSingleton.classSymbol
81-
val scrutClassSym = scrut.widenSingleton.classSymbol
80+
val patClassSym = pat.classSymbol
81+
val scrutClassSym = scrut.classSymbol
8282
!patClassSym.exists || !scrutClassSym.exists || {
8383
if (patClassSym.is(Final)) patClassSym.derivesFrom(scrutClassSym)
8484
else if (scrutClassSym.is(Final)) scrutClassSym.derivesFrom(patClassSym)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ object TypeOps:
752752
// variance. As this logic is only needed in exhaustivity check,
753753
// we manually patch subtyping check instead of changing TypeComparer.
754754
// See tests/patmat/i3645b.scala
755-
def parentQualify(tp1: Type, tp2: Type) = tp1.widen.classSymbol.info.parents.exists { parent =>
755+
def parentQualify(tp1: Type, tp2: Type) = tp1.classSymbol.info.parents.exists { parent =>
756756
parent.argInfos.nonEmpty && approximateTypeParams(parent) <:< tp2
757757
}
758758

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ object Types {
437437
if (sym.isClass) sym else tp.superType.classSymbol
438438
case tp: ClassInfo =>
439439
tp.cls
440-
case tp: SingletonType =>
441-
NoSymbol
442440
case tp: TypeProxy =>
443441
tp.underlying.classSymbol
444442
case AndType(l, r) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ArrayConstructors extends MiniPhase {
3434
}
3535
else if ((tree.fun.symbol.maybeOwner eq defn.ArrayModule.moduleClass) && (tree.fun.symbol.name eq nme.ofDim) && !tree.tpe.isInstanceOf[MethodicType]) {
3636
val Apply(Apply(TypeApply(_, List(tp)), _), _) = tree
37-
val cs = tp.tpe.widen.classSymbol
37+
val cs = tp.tpe.classSymbol
3838
tree.fun match {
3939
case Apply(TypeApply(t: Ident, targ), dims)
4040
if !TypeErasure.isGeneric(targ.head.tpe) && !ValueClasses.isDerivedValueClass(cs) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ object Erasure {
287287

288288
cast(tree1, pt)
289289
case _ =>
290-
val cls = pt.widen.classSymbol
290+
val cls = pt.classSymbol
291291
if (cls eq defn.UnitClass) constant(tree, Literal(Constant(())))
292292
else {
293293
assert(cls ne defn.ArrayClass)
@@ -430,7 +430,7 @@ object Erasure {
430430
val implResultType = implType.resultType
431431
val samResultType = sam.resultType
432432

433-
if (!defn.isSpecializableFunction(implClosure.tpe.widen.classSymbol.asClass, implParamTypes, implResultType)) {
433+
if (!defn.isSpecializableFunction(implClosure.tpe.classSymbol.asClass, implParamTypes, implResultType)) {
434434
def autoAdaptedParam(tp: Type) = !tp.isErasedValueType && !tp.isPrimitiveValueType
435435
val explicitSAMType = implClosure.tpt.tpe.exists
436436
def autoAdaptedResult(tp: Type) = !tp.isErasedValueType &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ object ExplicitOuter {
398398
count: Int = -1): Tree =
399399
try
400400
@tailrec def loop(tree: Tree, count: Int): Tree =
401-
val treeCls = tree.tpe.widen.classSymbol
401+
val treeCls = tree.tpe.classSymbol
402402
report.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${atPhaseNoLater(lambdaLiftPhase)(outerAccName(treeCls.asClass))} in $treeCls")
403403
if (count == 0 || count < 0 && treeCls == toCls) tree
404404
else

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FunctionalInterfaces extends MiniPhase {
2828
private val functionPackage = "dotty.runtime.function.".toTermName
2929

3030
override def transformClosure(tree: Closure)(using Context): Tree = {
31-
val cls = tree.tpe.widen.classSymbol.asClass
31+
val cls = tree.tpe.classSymbol.asClass
3232

3333
val implType = tree.meth.tpe.widen
3434
val List(implParamTypes) = implType.paramInfoss

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ object TypeUtils {
4141
case AppliedType(tycon, _ :: tl :: Nil) if tycon.isRef(defn.PairClass) =>
4242
val arity = tl.tupleArity
4343
if (arity < 0) arity else arity + 1
44-
case self: TermRef if self.symbol == defn.EmptyTupleModule =>
45-
0
44+
case self: SingletonType =>
45+
if self.termSymbol == defn.EmptyTupleModule then 0 else -1
4646
case self if defn.isTupleClass(self.classSymbol) =>
4747
self.dealias.argInfos.length
4848
case _ =>
@@ -53,7 +53,8 @@ object TypeUtils {
5353
def tupleElementTypes(using Context): List[Type] = self match {
5454
case AppliedType(tycon, hd :: tl :: Nil) if tycon.isRef(defn.PairClass) =>
5555
hd :: tl.tupleElementTypes
56-
case self: TermRef if self.symbol == defn.EmptyTupleModule =>
56+
case self: SingletonType =>
57+
assert(self.termSymbol == defn.EmptyTupleModule, "not a tuple")
5758
Nil
5859
case self if defn.isTupleClass(self.classSymbol) =>
5960
self.dealias.argInfos

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -645,26 +645,22 @@ class SpaceEngine(using Context) extends SpaceLogic {
645645

646646

647647
/** Abstract sealed types, or-types, Boolean and Java enums can be decomposed */
648-
def canDecompose(tp: Type): Boolean = {
649-
val dealiasedTp = tp.dealias
650-
val res =
651-
(tp.classSymbol.is(Sealed) &&
652-
tp.classSymbol.isOneOf(AbstractOrTrait) &&
653-
!tp.classSymbol.hasAnonymousChild &&
654-
tp.classSymbol.children.nonEmpty ) ||
655-
dealiasedTp.isInstanceOf[OrType] ||
656-
(dealiasedTp.isInstanceOf[AndType] && {
657-
val and = dealiasedTp.asInstanceOf[AndType]
658-
canDecompose(and.tp1) || canDecompose(and.tp2)
659-
}) ||
660-
tp.isRef(defn.BooleanClass) ||
661-
tp.isRef(defn.UnitClass) ||
662-
tp.classSymbol.isAllOf(JavaEnumTrait)
663-
648+
def canDecompose(tp: Type): Boolean =
649+
val res = tp.dealias match
650+
case _: SingletonType => false
651+
case _: OrType => true
652+
case and: AndType => canDecompose(and.tp1) || canDecompose(and.tp2)
653+
case _ =>
654+
val cls = tp.classSymbol
655+
cls.is(Sealed)
656+
&& cls.isOneOf(AbstractOrTrait)
657+
&& !cls.hasAnonymousChild
658+
&& cls.children.nonEmpty
659+
|| cls.isAllOf(JavaEnumTrait)
660+
|| tp.isRef(defn.BooleanClass)
661+
|| tp.isRef(defn.UnitClass)
664662
debug.println(s"decomposable: ${tp.show} = $res")
665-
666663
res
667-
}
668664

669665
/** Show friendly type name with current scope in mind
670666
*
@@ -765,7 +761,8 @@ class SpaceEngine(using Context) extends SpaceLogic {
765761
if (flattenList && tp <:< scalaNilType) ""
766762
else tp.symbol.showName
767763
case Typ(tp, decomposed) =>
768-
val sym = tp.widen.classSymbol
764+
765+
val sym = tp.classSymbol
769766

770767
if (ctx.definitions.isTupleType(tp))
771768
params(tp).map(_ => "_").mkString("(", ", ", ")")

0 commit comments

Comments
 (0)