This page is no longer maintained — Please continue to the home page at www.scala-lang.org

[scala-bts] #4103: incostistent scala.xml.Elem equality

1 reply
Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.

-----------------------+----------------------------------------------------
Reporter: aga | Owner: scala-xml_team
Type: defect | Status: new
Priority: normal | Component: XML support
Keywords: xml equals |
-----------------------+----------------------------------------------------
[scala 2.8.1]
One would expect that 'set.toSeq' will always contain the same elements as
'set', well, prehaps just in a different order? It is so frustrating to
find out that to be false:

{{{
import scala.xml._
import scala.collection.immutable

final case class Category (id: Int, parent: Int) {
override def hashCode() = id

override def equals (obj: Any): Boolean = {
if (!(obj.isInstanceOf[Category])) return false
id == obj.asInstanceOf[Category].id
}

def xml: Elem =
}

object test {
def main (params: Array[String]): Unit = {
var set = immutable.Set.empty[Category]
set += Category(1, 0)
set += Category(2, 1)
set += Category(3, 1)
System.err.println("set=" + (set map {_.xml} ))
System.err.println("set.seq=" + (set.toSeq map {_.xml} ))
}
}
}}}

The output (slightly formatted manually):
{{{
set=Set(
,

)
set.seq=List(
,
,

)
}}}

Oh no, that should not be so!

The set and set.toSeq objects themselves are ok; each has length of 3. It
is after mapping the set elements into scala.xml.Elem some elements are
starting to magically disappear.

This bug resembles #3334; but here the final set contains the exact same
type objects passed via the exact same mapping - it could not be more
trivial than this (on the user side). And it could not be harder to find
out where those categories disappear into...

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #4103: inconsistent scala.xml.Elem equality (was

------------------------+---------------------------------------------------
Reporter: aga | Owner: scala-xml_team
Type: defect | Status: closed
Priority: normal | Component: XML support
Resolution: duplicate | Keywords: xml equals
------------------------+---------------------------------------------------
Changes (by harrah):

* cc: harrah@… (added)
* status: new => closed
* resolution: => duplicate

Comment:

#3886, fixed in trunk

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland