Skip to content

Commit 5ad42d1

Browse files
committed
Be careful to always use .classSymbol to retrieve a parent symbol
Parent types can be aliases, so .typeSymbol can be wrong.
1 parent f8f5176 commit 5ad42d1

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,16 +1466,11 @@ object SymDenotations {
14661466
if (classParents.isEmpty && !emptyParentsExpected)
14671467
onBehalf.signalProvisional()
14681468
val builder = new BaseDataBuilder
1469-
for (p <- classParents) {
1470-
var pcls = p.typeSymbol
1471-
if (!pcls.isClass) pcls = p.underlyingClassRef(refinementOK = false).typeSymbol
1472-
// This roundabout way is necessary for avoiding cyclic references.
1473-
// A test case is CompilationTests.compileMixed
1474-
pcls match {
1469+
for (p <- classParents)
1470+
p.classSymbol match {
14751471
case pcls: ClassSymbol => builder.addAll(pcls.baseClasses)
14761472
case _ => assert(isRefinementClass || ctx.mode.is(Mode.Interactive), s"$this has non-class parent: $p")
14771473
}
1478-
}
14791474
(classSymbol :: builder.baseClasses, builder.baseClassSet)
14801475
}
14811476

@@ -1604,7 +1599,7 @@ object SymDenotations {
16041599
def collect(denots: PreDenotation, parents: List[Type]): PreDenotation = parents match {
16051600
case p :: ps =>
16061601
val denots1 = collect(denots, ps)
1607-
p.typeSymbol.denot match {
1602+
p.classSymbol.denot match {
16081603
case parentd: ClassDenotation =>
16091604
denots1 union
16101605
parentd.nonPrivateMembersNamed(name)
@@ -1753,7 +1748,7 @@ object SymDenotations {
17531748
var names = Set[Name]()
17541749
def maybeAdd(name: Name) = if (keepOnly(thisType, name)) names += name
17551750
for (p <- classParents)
1756-
for (name <- p.typeSymbol.asClass.memberNames(keepOnly))
1751+
for (name <- p.classSymbol.asClass.memberNames(keepOnly))
17571752
maybeAdd(name)
17581753
val ownSyms =
17591754
if (keepOnly eq implicitFilter)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CheckReentrant extends MiniPhase {
8282
}
8383
}
8484
for (parent <- cls.classInfo.classParents)
85-
addVars(parent.typeSymbol.asClass)
85+
addVars(parent.classSymbol.asClass)
8686
}
8787
}
8888
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ object GenericSignatures {
5353
val validParents =
5454
if (isTraitSignature)
5555
// java is unthrilled about seeing interfaces inherit from classes
56-
minParents filter (p => isInterfaceOrTrait(p.typeSymbol))
56+
minParents filter (p => isInterfaceOrTrait(p.classSymbol))
5757
else minParents
5858

5959
val ps = ensureClassAsFirstParent(validParents)
@@ -329,11 +329,11 @@ object GenericSignatures {
329329
def isUnshadowed(psym: Symbol) =
330330
!(psyms exists (qsym => (psym ne qsym) && (qsym isSubClass psym)))
331331
val cs = parents.iterator.filter { p => // isUnshadowed is a bit expensive, so try classes first
332-
val psym = p.typeSymbol
332+
val psym = p.classSymbol
333333
psym.ensureCompleted()
334334
psym.isClass && !psym.is(Trait) && isUnshadowed(psym)
335335
}
336-
(if (cs.hasNext) cs else parents.iterator.filter(p => isUnshadowed(p.typeSymbol))).next()
336+
(if (cs.hasNext) cs else parents.iterator.filter(p => isUnshadowed(p.classSymbol))).next()
337337
}
338338
}
339339
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ trait ImplicitRunInfo { self: Run =>
449449
comps += companion.asSeenFrom(pre, compSym.owner).asInstanceOf[TermRef]
450450
}
451451
def addParentScope(parent: Type): Unit =
452-
iscopeRefs(tp.baseType(parent.typeSymbol)) foreach addRef
452+
iscopeRefs(tp.baseType(parent.classSymbol)) foreach addRef
453453
val companion = cls.companionModule
454454
if (companion.exists) addRef(companion.termRef)
455455
cls.classParents foreach addParentScope

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ object RefChecks {
103103
cls.pos)
104104
}
105105
for (parent <- cinfo.classParents)
106-
checkSelfConforms(parent.typeSymbol.asClass, "illegal inheritance", "parent")
106+
checkSelfConforms(parent.classSymbol.asClass, "illegal inheritance", "parent")
107107
for (reqd <- cinfo.cls.givenSelfType.classSymbols)
108108
checkSelfConforms(reqd, "missing requirement", "required")
109109
case _ =>

tests/neg/parser-stability-21.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class x0[x1[]] // error
2+
extends x1[ // error // error

0 commit comments

Comments
 (0)