diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2010-06-29 14:19:42 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2010-06-29 14:19:42 +0000 |
commit | 24a694fe23cdd9f13e110e3ce2036556a0ef18a9 (patch) | |
tree | ad28cdf8847ce482de76658d6e7cf44ad6d85e3d /src/compiler | |
parent | 52b863dd86ae854328f74d1d05ca71b2915fa7d7 (diff) | |
download | scala-24a694fe23cdd9f13e110e3ce2036556a0ef18a9.tar.gz scala-24a694fe23cdd9f13e110e3ce2036556a0ef18a9.tar.bz2 scala-24a694fe23cdd9f13e110e3ce2036556a0ef18a9.zip |
companion objects of case classes know their name.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Unapplies.scala | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala index 5bbda13acd..c3631f0d05 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala @@ -130,21 +130,28 @@ trait Unapplies extends ast.TreeDSL } } - /** The module corresponding to a case class; without any member definitions + /** The module corresponding to a case class; overrides toString to show the module's name */ def caseModuleDef(cdef: ClassDef): ModuleDef = { def inheritFromFun = !(cdef.mods hasFlag ABSTRACT) && cdef.tparams.isEmpty && constrParamss(cdef).length == 1 def createFun = gen.scalaFunctionConstr(constrParamss(cdef).head map (_.tpt), toIdent(cdef), abstractFun = true) def parents = if (inheritFromFun) List(createFun) else Nil - - companionModuleDef(cdef, parents ::: List(gen.scalaScalaObjectConstr)) + def toString = DefDef( + Modifiers(OVERRIDE | FINAL), + nme.toString_, + Nil, + List(Nil), + TypeTree(), + Literal(Constant(cdef.name.decode))) + + companionModuleDef(cdef, parents ::: List(gen.scalaScalaObjectConstr), List(toString)) } - def companionModuleDef(cdef: ClassDef, parents: List[Tree]): ModuleDef = atPos(cdef.pos.focus) { + def companionModuleDef(cdef: ClassDef, parents: List[Tree], body: List[Tree] = Nil): ModuleDef = atPos(cdef.pos.focus) { ModuleDef( Modifiers(cdef.mods.flags & AccessFlags | SYNTHETIC, cdef.mods.privateWithin), cdef.name.toTermName, - Template(parents, emptyValDef, NoMods, Nil, List(Nil), Nil, cdef.impl.pos.focus)) + Template(parents, emptyValDef, NoMods, Nil, List(Nil), body, cdef.impl.pos.focus)) } private val caseMods = Modifiers(SYNTHETIC | CASE) |