From a40276ad9a846248d9bd76ebc58b836522f7c36e Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Fri, 15 Jan 2010 14:41:19 +0000 Subject: Fixed issue when searching for companion of cla... Fixed issue when searching for companion of class using "linkedSym" when value of same name is overloaded (for example companion of the Value class in an Enumeration). No review, already checked by odersky. --- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 85ed3a786f..5ee7409cc7 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -1254,21 +1254,28 @@ trait Symbols { else NoSymbol } + /** A helper method that factors the common code used the discover a companion module of a class. If a companion + * module exists, its symbol is returned, otherwise, `NoSymbol` is returned. The method assumes that `this` + * symbol has already been checked to be a class (using `isClass`). */ + private final def linkedModuleOfClass0: Symbol = + flatOwnerInfo.decl(name.toTermName).suchThat( + sym => (sym hasFlag MODULE) && (sym isCoDefinedWith this)) + /** The module or case class factory with the same name in the same * package as this class. A better name would be companionModuleOfClass. */ final def linkedModuleOfClass: Symbol = - if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass) { - flatOwnerInfo.decl(name.toTermName).suchThat( - sym => (sym hasFlag MODULE) && (sym isCoDefinedWith this)) - } else NoSymbol + if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass) + linkedModuleOfClass0 + else NoSymbol /** For a module its linked class, for a class its linked module or case * factory otherwise. */ final def linkedSym: Symbol = if (isTerm) linkedClassOfModule - else if (isClass) flatOwnerInfo.decl(name.toTermName).suchThat(_ isCoDefinedWith this) + else if (isClass) + linkedModuleOfClass0 else NoSymbol /** For a module class its linked class, for a plain class -- cgit v1.2.3