diff options
author | Martin Odersky <odersky@gmail.com> | 2008-02-13 15:29:23 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2008-02-13 15:29:23 +0000 |
commit | a9ce75094658fa546d50d64e27e34c145d1a7b62 (patch) | |
tree | 3d4cc4ff55743aa91bd21c61aadcd3951a9bab14 /src | |
parent | 928dce3cfa08ce3a4d5c92e31840b0ccb0e3135f (diff) | |
download | scala-a9ce75094658fa546d50d64e27e34c145d1a7b62.tar.gz scala-a9ce75094658fa546d50d64e27e34c145d1a7b62.tar.bz2 scala-a9ce75094658fa546d50d64e27e34c145d1a7b62.zip |
change to caseclass extractors with varargs
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Unapplies.scala | 13 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index b6dd026a84..3cfb6ccc76 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -156,6 +156,12 @@ abstract class TreeInfo { case _ => false } + /** Is type a of the form T* ? */ + def isRepeatedParamType(tpt: Tree) = tpt match { + case AppliedTypeTree(Select(_, rp), _) => rp == nme.REPEATED_PARAM_CLASS_NAME.toTypeName + case _ => false + } + /** Is name a left-associative operator? */ def isLeftAssoc(operator: Name): Boolean = operator.length > 0 && operator(operator.length - 1) != ':' diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala index 334e6d1f48..94c9d9865a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala @@ -150,11 +150,8 @@ trait Unapplies { self: Analyzer => val tparams = cdef.tparams map copyUntyped[TypeDef] def paramToArg(param: ValDef) = { val id = Ident(param.name) - val RP = nme.REPEATED_PARAM_CLASS_NAME.toTypeName - param.tpt match { - case AppliedTypeTree(Select(_, RP), _) => Typed(id, Ident(nme.WILDCARD_STAR.toTypeName)) - case _ => id - } + if (treeInfo.isRepeatedParamType(param.tpt)) Typed(id, Ident(nme.WILDCARD_STAR.toTypeName)) + else id } val cparams = constrParams(cdef) atPos(cdef.pos) { @@ -173,10 +170,14 @@ trait Unapplies { self: Analyzer => def caseModuleUnapplyMeth(cdef: ClassDef): DefDef = { val tparams = cdef.tparams map copyUntyped[TypeDef] val unapplyParamName = newTermName("x$0") + val hasVarArg = constrParams(cdef) match { + case cps :: _ => treeInfo.isRepeatedParamType(cps.last.tpt) + case _ => false + } atPos(cdef.pos) { DefDef( Modifiers(SYNTHETIC | CASE), - nme.unapply, + if (hasVarArg) nme.unapplySeq else nme.unapply, tparams, List(List(ValDef(Modifiers(PARAM | SYNTHETIC), unapplyParamName, classType(cdef, tparams), EmptyTree))), |