From 610fdb6b5ae6e6a7b74681f0623aefb937952cfe Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 22 Dec 2010 11:29:12 +0000 Subject: Fix 'Symbol.companionModule' for the resident m... Fix 'Symbol.companionModule' for the resident mode compiler. It was confused by having modules being translated to lazy values. The direct consequence was a crash in the build manager when looking at a constructor using a default argument (compiled separately), but only on the second run. 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. review by odersky. --- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src') 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. -- cgit v1.2.3