diff options
author | Dmitry Petrashko <dark@d-d.me> | 2017-04-04 12:03:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 12:03:18 +0200 |
commit | abd09ff1fcd4a43b67b1dc029f1d375d0e1b57b9 (patch) | |
tree | 83c5a71bbc16e1185586b6aa4f1f4572a3d0a61a /compiler | |
parent | f8b058049953b5762088ccd450a4f7866e0204ef (diff) | |
parent | 466065a0db976f644149625237af0544d9fe16fa (diff) | |
download | dotty-abd09ff1fcd4a43b67b1dc029f1d375d0e1b57b9.tar.gz dotty-abd09ff1fcd4a43b67b1dc029f1d375d0e1b57b9.tar.bz2 dotty-abd09ff1fcd4a43b67b1dc029f1d375d0e1b57b9.zip |
Merge pull request #2149 from dotty-staging/fix/false-companion-2
Create dummy companions for classes without a real one
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Namer.scala | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 4077d8d65..94506f318 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -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) @@ -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) + } + } + } } } |