Skip to content

Commit e5c957e

Browse files
committed
Fix regression in 5751763
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.
1 parent 23e5ed9 commit e5c957e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ abstract class SymbolLoaders {
122122
* and give them `completer` as type.
123123
*/
124124
def enterClassAndModule(root: Symbol, name: String, getCompleter: (ClassSymbol, ModuleSymbol) => SymbolLoader) {
125-
val clazz = newClass(root, name)
126-
val module = newModule(root, name)
127-
val completer = getCompleter(clazz, module)
128-
enterClass(root, clazz, completer)
129-
enterModule(root, module, completer)
125+
val clazz0 = newClass(root, name)
126+
val module0 = newModule(root, name)
127+
val completer = getCompleter(clazz0, module0)
128+
// enterClass/Module may return an existing symbol instead of the ones we created above
129+
// this may happen when there's both sources and binaries on the classpath, but the class
130+
// name is different from the file name, so the classpath can't match the binary and source
131+
// representation. `companionModule/Class` prefers the source version, so we should be careful
132+
// to reuse the symbols returned below.
133+
val clazz = enterClass(root, clazz0, completer)
134+
val module = enterModule(root, module0, completer)
130135
if (!clazz.isAnonymousClass) {
131136
// Diagnostic for SI-7147
132137
def msg: String = {

0 commit comments

Comments
 (0)