summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-03-05 19:19:17 +0000
committerPaul Phillips <paulp@improving.org>2010-03-05 19:19:17 +0000
commit0433d8843272b174d0ce0b7eb3c0ed806bc2705a (patch)
tree043843abf0623505472fb7898fb3ce769d77a572 /src
parent603f715f52462de73481fd79e12c0deec68d269e (diff)
downloadscala-0433d8843272b174d0ce0b7eb3c0ed806bc2705a.tar.gz
scala-0433d8843272b174d0ce0b7eb3c0ed806bc2705a.tar.bz2
scala-0433d8843272b174d0ce0b7eb3c0ed806bc2705a.zip
ScalaRunTime method to perform sameElements as ...
ScalaRunTime method to perform sameElements as fix for #2867. Review by odersky.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala25
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala7
3 files changed, 16 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 68c75a721a..3d969a53b4 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -152,6 +152,7 @@ trait Definitions extends reflect.generic.StandardDefinitions {
def arrayLengthMethod = getMember(ScalaRunTimeModule, "array_length")
def arrayCloneMethod = getMember(ScalaRunTimeModule, "array_clone")
def scalaRuntimeHash = getMember(ScalaRunTimeModule, "hash")
+ def scalaRuntimeSameElements = getMember(ScalaRunTimeModule, nme.sameElements)
// classes with special meanings
lazy val NotNullClass = getClass("scala.NotNull")
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index 6a68ddc68c..042343ac16 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -180,23 +180,14 @@ trait SyntheticMethods extends ast.TreeDSL {
// returns (Apply, Bind)
def makeTrees(acc: Symbol, cpt: Type): (Tree, Bind) = {
- val varName = context.unit.fresh.newName(clazz.pos.focus, acc.name + "$")
- val (eqMethod, binding) =
- if (isRepeatedParamType(cpt)) (nme.sameElements, Star(WILD()))
- else (nme.EQ , WILD() )
-
- ((varName DOT eqMethod)(Ident(acc)), varName BIND binding)
-/** The three lines above were replaced by the following to fix #2867. But this makes lift fail, because
- * an explicitly given type paramter violates its bound. Not sure what to do here.
- *
- if (isRepeatedParamType(cpt))
- (TypeApply(varName DOT nme.sameElements, List(TypeTree(cpt.baseType(SeqClass).typeArgs.head))),
- Star(WILD()))
- else
- ((varName DOT nme.EQ): Tree,
- WILD())
- (eqMethod APPLY Ident(acc), varName BIND binding)
- */
+ val varName = context.unit.fresh.newName(clazz.pos.focus, acc.name + "$")
+ val isRepeated = isRepeatedParamType(cpt)
+ val binding = if (isRepeated) Star(WILD()) else WILD()
+ val eqMethod: Tree =
+ if (isRepeated) gen.mkRuntimeCall(nme.sameElements, List(Ident(varName), Ident(acc)))
+ else (varName DOT nme.EQ)(Ident(acc))
+
+ (eqMethod, varName BIND binding)
}
// Creates list of parameters and a guard for each
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 82573bf4b1..d04824bae1 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -179,6 +179,13 @@ object ScalaRunTime {
*/
@inline def hash(x: Any): Int = Predef.hash(x)
+ /** A helper method for constructing case class equality methods,
+ * because existential types get in the way of a clean outcome and
+ * it's performing a series of Any/Any equals comparisons anyway.
+ * See ticket #2867 for specifics.
+ */
+ def sameElements(xs1: Seq[Any], xs2: Seq[Any]) = xs1 sameElements xs2
+
/** Given any Scala value, convert it to a String.
*
* The primary motivation for this method is to provide a means for