Skip to content

Commit abd09ff

Browse files
authored
Merge pull request #2149 from dotty-staging/fix/false-companion-2
Create dummy companions for classes without a real one
2 parents f8b0580 + 466065a commit abd09ff

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,11 @@ class Namer { typer: Typer =>
606606
}
607607
}
608608

609-
// If a top-level object has no companion class in the current run, we
610-
// enter a dummy companion class symbol (`denot.isAbsent` returns true) in
611-
// scope. This ensures that we never use a companion from a previous run
612-
// or from the classpath. See tests/pos/false-companion for an
613-
// example where this matters.
609+
// If a top-level object or class has no companion in the current run, we
610+
// enter a dummy companion (`denot.isAbsent` returns true) in scope. This
611+
// ensures that we never use a companion from a previous run or from the
612+
// classpath. See tests/pos/false-companion for an example where this
613+
// matters.
614614
if (ctx.owner.is(PackageClass)) {
615615
for (cdef @ TypeDef(moduleName, _) <- moduleDef.values) {
616616
val moduleSym = ctx.effectiveScope.lookup(moduleName.encode)
@@ -623,6 +623,17 @@ class Namer { typer: Typer =>
623623
}
624624
}
625625
}
626+
for (cdef @ TypeDef(className, _) <- classDef.values) {
627+
val classSym = ctx.effectiveScope.lookup(className.encode)
628+
if (classSym.isDefinedInCurrentRun) {
629+
val moduleName = className.toTermName
630+
val moduleSym = ctx.effectiveScope.lookup(moduleName.encode)
631+
if (!moduleSym.isDefinedInCurrentRun) {
632+
val absentModuleSymbol = ctx.newModuleSymbol(ctx.owner, moduleName, EmptyFlags, EmptyFlags, (_, _) => NoType)
633+
enterSymbol(absentModuleSymbol)
634+
}
635+
}
636+
}
626637
}
627638
}
628639

0 commit comments

Comments
 (0)