Aladdin - Scala Bugtracking
[#861] project: compiler priority: low category: bug
submitter assigned to status date submitted
Burak _ _ 2006-12-04 11:43:57.0
subject equals method broken for varargs case classes
code
import scala.testing.SUnit.Assert

object Foo extends Assert {
  case class Bar(x:String*)

  val z = List("foo","bar")
  val y = Array("foo","bar")

  def main(args:Array[String]) = {
    assertTrue(Bar(z:_*) == Bar(y:_*))
  }
}
what happened
$ Documents/svn/scala/build/quick/bin/scalac -d /tmp /tmp/broken.scala 
$ Documents/svn/scala/build/quick/bin/scala -classpath /tmp Foo
failed assertion:(no message)
        at scala.testing.SUnit$Assert$class.fail(SUnit.scala:193)
        at Foo$.fail(broken.scala:3)
        at scala.testing.SUnit$Assert$class.assertEquals(SUnit.scala:136)
        at Foo$.assertEquals(broken.scala:3)
        at scala.testing.SUnit$Assert$class.assertTrue(SUnit.scala:184)
        at Foo$.assertTrue(broken.scala:3)
        at scala.testing.SUnit$Assert$class.assertTrue(SUnit.scala:188)
        at Foo$.assertTrue(broken.scala:3)
        at Foo$.main(broken.scala:10)
        at Foo.main(broken.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:76)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:100)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
what expected The equals test to be defined properly for case classes with iterated parameters. One option to do is to change the equals method to use "sameElements".
def equals = compare elements but the last with equals, the last with sameElements
The other is to generate arity and element implementations to which the sequence representation is transparent.
def arity = {n. fixed members} -1 + {access last member()}.length
def element(i:Int) = if(i < n. fixed members) {return fixed member_i()} else {
  return last member().( i )
}
[back to overview]
Changes of this bug report