Skip to content

Commit

Permalink
Fix regression in 5751763
Browse files Browse the repository at this point in the history
enterClass/Module may return an existing symbol, but in 5751763 the return value was dropped leading to assertion failures. This may show up only in the presentation compiler, which explains why it went unnoticed.

Here's what needs to happen:

- a class with a companion is loaded by the IDE, but the class name is different than the file name. This is from source
- the same class and companion object exist as binary, and are loaded from classfiles when the package is completed (since they have different names than the source file, the classpath abstraction will only "know" that there is a classfile, and no corresponding source file)

It seems that companionClass always prefers to return the companion defined in a source file, but if this assertion is called from the code path that tries to load the binary version, the newly created module will not match.
  • Loading branch information
dragos committed Feb 22, 2017
1 parent 23e5ed9 commit e5c957e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
Expand Up @@ -122,11 +122,16 @@ abstract class SymbolLoaders {
* and give them `completer` as type.
*/
def enterClassAndModule(root: Symbol, name: String, getCompleter: (ClassSymbol, ModuleSymbol) => SymbolLoader) {
val clazz = newClass(root, name)
val module = newModule(root, name)
val completer = getCompleter(clazz, module)
enterClass(root, clazz, completer)
enterModule(root, module, completer)
val clazz0 = newClass(root, name)
val module0 = newModule(root, name)
val completer = getCompleter(clazz0, module0)
// enterClass/Module may return an existing symbol instead of the ones we created above
// this may happen when there's both sources and binaries on the classpath, but the class
// name is different from the file name, so the classpath can't match the binary and source
// representation. `companionModule/Class` prefers the source version, so we should be careful
// to reuse the symbols returned below.
val clazz = enterClass(root, clazz0, completer)
val module = enterModule(root, module0, completer)
if (!clazz.isAnonymousClass) {
// Diagnostic for SI-7147
def msg: String = {
Expand Down

0 comments on commit e5c957e

Please sign in to comment.