summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2017-02-20 16:38:29 +0100
committerIulian Dragos <jaguarul@gmail.com>2017-02-22 20:28:32 +0100
commite5c957e764c5869e97da7d0dd8fec1bc86283e22 (patch)
tree76ae438750a3c95e85ac9904a8fceb35a16fe00a /src
parent23e5ed9219b503c6a394b28d014ea5c29893db8d (diff)
downloadscala-e5c957e764c5869e97da7d0dd8fec1bc86283e22.tar.gz
scala-e5c957e764c5869e97da7d0dd8fec1bc86283e22.tar.bz2
scala-e5c957e764c5869e97da7d0dd8fec1bc86283e22.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
index d948d151a6..dd44366692 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -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 = {