Removed what amounted to a no-operation in the synthetic

case class equals method, and removed some dead code at the
source level as well.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@18080 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2009-06-22 22:26:59 +00:00
parent 41b93f72d1
commit 03a7028e83
1 changed files with 31 additions and 51 deletions

View File

@ -138,14 +138,16 @@ trait SyntheticMethods { self: Analyzer =>
localTyper.typed(methodDef)
}
/** The equality method for case classes:
/** The equality method for case classes. The argument is an Any,
* but because of boxing it will always be an Object, so a check
* is neither necessary nor useful before the cast.
*
* def equals(that: Any) =
* that.isInstanceOf[AnyRef] &&
* ((this eq that.asInstanceOf[AnyRef]) ||
* (this eq that.asInstanceOf[AnyRef]) ||
* (that match {
* case this.C(this.arg_1, ..., this.arg_n) => true
* case _ => false
* }))
* })
*/
def equalsClassMethod: Tree = {
val method = equalsSym
@ -155,19 +157,6 @@ trait SyntheticMethods { self: Analyzer =>
val that = Ident(method.paramss.head.head)
val constrParamTypes = clazz.primaryConstructor.tpe.paramTypes
val hasVarArgs = !constrParamTypes.isEmpty && constrParamTypes.last.typeSymbol == RepeatedParamClass
if (false && clazz.isStatic) {
// todo: elim
val target = getMember(ScalaRunTimeModule, if (hasVarArgs) nme._equalsWithVarArgs else nme._equals)
Apply(
Select(
TypeApply(
Select(that, Any_isInstanceOf),
List(TypeTree(clazz.tpe))),
Boolean_and),
List(
Apply(gen.mkAttributedRef(target),
This(clazz) :: (method.paramss.head map Ident))))
} else {
val (pat, guard) = {
val guards = new ListBuffer[Tree]
val params = for ((acc, cpt) <- clazz.caseFieldAccessors zip constrParamTypes) yield {
@ -189,21 +178,12 @@ trait SyntheticMethods { self: Analyzer =>
}
)
}
val isAnyRef = TypeApply(
Select(that, Any_isInstanceOf),
List(TypeTree(AnyRefClass.tpe)))
val cast = TypeApply(
Select(that, Any_asInstanceOf),
List(TypeTree(AnyRefClass.tpe)))
val eq_ = Apply(Select( This(clazz) , nme.eq), List(that setType AnyRefClass.tpe))
val eq_ = Apply(Select(This(clazz), nme.eq), List(that setType AnyRefClass.tpe))
val match_ = Match(that, List(
CaseDef(pat, guard, Literal(Constant(true))),
CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false)))))
Apply(
Select(isAnyRef, Boolean_and),
List(Apply(Select(eq_, Boolean_or),
List(match_))))
}
gen.mkOr(eq_, match_)
}
)
localTyper.typed(methodDef)