summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 62540527e8..543dac1665 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -1264,14 +1264,24 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
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`).
- * After refchecks nested objects get transformed to lazy vals so we filter on LAZY flag*/
+ /** 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`).
+ *
+ * After refchecks nested objects get transformed to lazy vals so we filter on LAZY flag as well.
+ * @note The resident compiler may run many times over, and symbols may be reused. Therefore, a
+ * module symbol that has been translated to a lazy val by refchecks is not guaranteed to
+ * have MODULE set on the next run (even before refcheck). Flags are not part of symbol
+ * history. Instead we rely on the fact that a synthetic lazy value must have been a
+ * module.
+ */
private final def companionModule0: Symbol = {
- val f = if (phase.refChecked && isNestedClass && !forMSIL) LAZY else MODULE
+ def isSyntheticLazy(sym: Symbol) =
+ (sym.hasAllFlags(LAZY | SYNTHETIC))
+
flatOwnerInfo.decl(name.toTermName).suchThat(
- sym => (sym hasFlag f) && (sym isCoDefinedWith this))
+ sym => (sym isCoDefinedWith this)
+ && (sym.hasFlag(MODULE) || isSyntheticLazy(sym)))
}
/** For a class: the module or case class factory wiht the same name in the same package.