Skip to content

Create dummy companions for classes without a real one #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,11 @@ class Namer { typer: Typer =>
}
}

// If a top-level object has no companion class in the current run, we
// enter a dummy companion class symbol (`denot.isAbsent` returns true) in
// scope. This ensures that we never use a companion from a previous run
// or from the classpath. See tests/pos/false-companion for an
// example where this matters.
// If a top-level object or class has no companion in the current run, we
// enter a dummy companion (`denot.isAbsent` returns true) in scope. This
// ensures that we never use a companion from a previous run or from the
// classpath. See tests/pos/false-companion for an example where this
// matters.
if (ctx.owner.is(PackageClass)) {
for (cdef @ TypeDef(moduleName, _) <- moduleDef.values) {
val moduleSym = ctx.effectiveScope.lookup(moduleName.encode)
Expand All @@ -623,6 +623,17 @@ class Namer { typer: Typer =>
}
}
}
for (cdef @ TypeDef(className, _) <- classDef.values) {
val classSym = ctx.effectiveScope.lookup(className.encode)
if (classSym.isDefinedInCurrentRun) {
val moduleName = className.toTermName
val moduleSym = ctx.effectiveScope.lookup(moduleName.encode)
if (!moduleSym.isDefinedInCurrentRun) {
val absentModuleSymbol = ctx.newModuleSymbol(ctx.owner, moduleName, EmptyFlags, EmptyFlags, (_, _) => NoType)
enterSymbol(absentModuleSymbol)
}
}
}
}
}

Expand Down