Skip to content

Commit

Permalink
SI-5956 trigger copy generation with correct namer
Browse files Browse the repository at this point in the history
the call to `addCopyMethod` passes `templateNamer`, which is supposed to be the
namer of the case class template. with two classes of the same name, `addCopyMethod`
was triggered in the wrong template.
  • Loading branch information
lrytz committed Jul 13, 2012
1 parent 758f0a7 commit 2c5890b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Namers.scala
Expand Up @@ -835,13 +835,15 @@ trait Namers extends MethodSynthesis {

// add the copy method to case classes; this needs to be done here, not in SyntheticMethods, because
// the namer phase must traverse this copy method to create default getters for its parameters.
// here, clazz is the ClassSymbol of the case class (not the module).
if (clazz.isClass && !clazz.hasModuleFlag) {
// here, clazz is the ClassSymbol of the case class (not the module). (!clazz.hasModuleFlag) excludes
// the moduleClass symbol of the companion object when the companion is a "case object".
if (clazz.isCaseClass && !clazz.hasModuleFlag) {
val modClass = companionSymbolOf(clazz, context).moduleClass
modClass.attachments.get[ClassForCaseCompanionAttachment] foreach { cma =>
val cdef = cma.caseClass
def hasCopy(decls: Scope) = (decls lookup nme.copy) != NoSymbol
if (cdef.mods.isCase && !hasCopy(decls) &&
// SI-5956 needs (cdef.symbol == clazz): there can be multiple class symbols with the same name
if (cdef.symbol == clazz && !hasCopy(decls) &&
!parents.exists(p => hasCopy(p.typeSymbol.info.decls)) &&
!parents.flatMap(_.baseClasses).distinct.exists(bc => hasCopy(bc.info.decls)))
addCopyMethod(cdef, templateNamer)
Expand Down
6 changes: 1 addition & 5 deletions test/files/neg/t1286.check
@@ -1,9 +1,5 @@
a.scala:1: error: Companions 'object Foo' and 'trait Foo' must be defined in same file:
Found in t1286/b.scala and t1286/a.scala
trait Foo {
^
b.scala:1: error: Companions 'trait Foo' and 'object Foo' must be defined in same file:
Found in t1286/a.scala and t1286/b.scala
object Foo extends Foo {
^
two errors found
one error found
20 changes: 20 additions & 0 deletions test/files/neg/t5956.check
@@ -0,0 +1,20 @@
t5956.scala:1: warning: case classes without a parameter list have been deprecated;
use either case objects or case classes with `()' as parameter list.
object O { case class C[T]; class C }
^
t5956.scala:2: warning: case classes without a parameter list have been deprecated;
use either case objects or case classes with `()' as parameter list.
object T { case class C[T]; case class C }
^
t5956.scala:2: warning: case classes without a parameter list have been deprecated;
use either case objects or case classes with `()' as parameter list.
object T { case class C[T]; case class C }
^
t5956.scala:1: error: C is already defined as case class C
object O { case class C[T]; class C }
^
t5956.scala:2: error: C is already defined as case class C
object T { case class C[T]; case class C }
^
three warnings found
two errors found
2 changes: 2 additions & 0 deletions test/files/neg/t5956.scala
@@ -0,0 +1,2 @@
object O { case class C[T]; class C }
object T { case class C[T]; case class C }

0 comments on commit 2c5890b

Please sign in to comment.