Skip to content

Commit 8490251

Browse files
committed
Survive bad symbols of module vals
Also: fix a cyclic reference caused by 5252b15
1 parent 06bd76e commit 8490251

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,11 @@ object SymDenotations {
14671467
onBehalf.signalProvisional()
14681468
val builder = new BaseDataBuilder
14691469
for (p <- classParents) {
1470-
p.underlyingClassRef(refinementOK = false).typeSymbol match {
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 {
14711475
case pcls: ClassSymbol => builder.addAll(pcls.baseClasses)
14721476
case _ => assert(isRefinementClass || ctx.mode.is(Mode.Interactive), s"$this has non-class parent: $p")
14731477
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ object NamerContextOps {
164164
/** Find moduleClass/sourceModule in effective scope */
165165
private def findModuleBuddy(name: Name, scope: Scope)(implicit ctx: Context) = {
166166
val it = scope.lookupAll(name).filter(_ is Module)
167-
assert(it.hasNext, s"no companion $name in $scope")
168-
it.next()
167+
if (it.hasNext) it.next()
168+
else {
169+
assert(ctx.reporter.errorsReported, s"no companion $name in $scope")
170+
NoSymbol
171+
}
169172
}
170173
}
171174

@@ -1033,8 +1036,11 @@ class Namer { typer: Typer =>
10331036
*/
10341037
def moduleValSig(sym: Symbol)(implicit ctx: Context): Type = {
10351038
val clsName = sym.name.moduleClassName
1036-
val cls = ctx.denotNamed(clsName) suchThat (_ is ModuleClass)
1037-
ctx.owner.thisType select (clsName, cls)
1039+
val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass).orElse {
1040+
assert(ctx.reporter.errorsReported)
1041+
ctx.newStubSymbol(ctx.owner, clsName)
1042+
}
1043+
ctx.owner.thisType.select(clsName, cls)
10381044
}
10391045

10401046
/** The type signature of a ValDef or DefDef

tests/neg/parser-stability-14.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object x0 {
2+
{
3+
val x1 x0 // error
4+
object x1 // error // error

tests/neg/parser-stability-16.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class x0[x0] {
2+
val x1 : x0
3+
}
4+
trait x3 extends x0 {
5+
x1 = 0 object // error // error

0 commit comments

Comments
 (0)