summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Namers.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2010-08-27 08:54:49 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2010-08-27 08:54:49 +0000
commit799a2b0e28ba78f607fb729bb350f6e3733c4845 (patch)
treef8e80567b8e9969b911de2c72ba3722a3a0825b7 /src/compiler/scala/tools/nsc/typechecker/Namers.scala
parentd20380ea9a6a36f227ff8d53f8fdb616067ccde8 (diff)
downloadscala-799a2b0e28ba78f607fb729bb350f6e3733c4845.tar.gz
scala-799a2b0e28ba78f607fb729bb350f6e3733c4845.tar.bz2
scala-799a2b0e28ba78f607fb729bb350f6e3733c4845.zip
partial fix for see #3772.
{{{ scala> def g { case class C(); object C; } <console>:5: error: C is already defined as (compiler-generated) case class companion object C def g { case class C(); object C; } ^ }}} review by odersky
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Namers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index cd5de7cb7b..235f067c95 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -288,8 +288,10 @@ trait Namers { self: Analyzer =>
* @return the companion object symbol.
*/
def ensureCompanionObject(tree: ClassDef, creator: => Tree): Symbol = {
- val m: Symbol = context.scope.lookup(tree.name.toTermName).filter(! _.isSourceMethod)
- if (m.isModule && inCurrentScope(m) && currentRun.compiles(m)) m
+ val m = companionModuleOf(tree.symbol, context)
+ // @luc: not sure why "currentRun.compiles(m)" is needed, things breaks
+ // otherwise. documentation welcome.
+ if (m != NoSymbol && currentRun.compiles(m)) m
else enterSyntheticSym(creator)
}
@@ -1364,6 +1366,25 @@ trait Namers { self: Analyzer =>
} else member.accessed
} else member
+ /**
+ * Finds the companion module of a class symbol. Calling .companionModule
+ * does not work for classes defined inside methods.
+ */
+ def companionModuleOf(clazz: Symbol, context: Context) = {
+ var res = clazz.companionModule
+ if (res == NoSymbol)
+ res = context.lookup(clazz.name.toTermName, clazz.owner).suchThat(sym =>
+ sym.hasFlag(MODULE) && sym.isCoDefinedWith(clazz))
+ res
+ }
+
+ def companionClassOf(module: Symbol, context: Context) = {
+ var res = module.companionClass
+ if (res == NoSymbol)
+ res = context.lookup(module.name.toTypeName, module.owner).suchThat(_.isCoDefinedWith(module))
+ res
+ }
+
/** An explanatory note to be added to error messages
* when there's a problem with abstract var defs */
def varNotice(sym: Symbol): String =