- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
[scala-bts] #3886: Elements generated in a for loop embedded in XML mysteriously disappear
Fri, 2010-10-01, 14:18
-------------------+--------------------------------------------------------
Reporter: ilyabo | Owner: scala-xml_team
Type: defect | Status: new
Priority: normal | Component: XML support
Keywords: XML |
-------------------+--------------------------------------------------------
Depending on the names of the generated elements' attributes (and their
casing) either all of the elements are retained in the output XML or just
the first one:
{{{
scala> { for (a <- Set("A","B","C")) yield { } }
res0: scala.xml.Elem =
scala> { for (a <- Set("A","B","C")) yield { } }
res1: scala.xml.Elem =
scala> { for (a <- Set("A","B","C")) yield { } }
res2: scala.xml.Elem =
scala> { for (a <- Set("A","B","C")) yield { } }
res3: scala.xml.Elem =
scala> { for (a <- Set("A","B","C")) yield { } }
res4: scala.xml.Elem =
scala> { for (a <- attrs) yield { }
}
res24: scala.xml.Elem =
}}}
It seems to be connected with the final ordering of the attributes in the
element.
Same problem, but with the map function instead of the for loop:
{{{
scala> class Key(id:String) { def toXml() = }
defined class Key
scala> { Set(new Key("A"), new Key("B"), new Key("C")).map(_.toXml())
}
res5: scala.xml.Elem =
scala> { Set(new Key("A"), new Key("B"), new Key("C")).map(_.toXml())
}
res6: scala.xml.Elem =
}}}
But not when the elements are manually specified:
{{{
scala>
res5: scala.xml.Elem =
}}}
Using scala-2.8.0-final
Can also be reproduced with the nightly build 2.8.1.r23161-b20101001023236
Wed, 2010-10-20, 08:47
#2
Re: [scala-bts] #3886: Elements generated in a for loop embedded
-------------------+--------------------------------------------------------
Reporter: ilyabo | Owner: scala-xml_team
Type: defect | Status: new
Priority: normal | Component: XML support
Version: | Keywords: XML
-------------------+--------------------------------------------------------
Changes (by extempore):
* cc: paulp@… (added)
Comment:
Can't remove MetaData's method: not being used in trunk doesn't mean not
being used. (Anyone can subclass it, not that I know why they would.)
Comparing all the attributes does seem like a good idea though.
Wed, 2010-10-20, 08:57
#3
Re: [scala-bts] #3886: Elements generated in a for loop embedded
-------------------+--------------------------------------------------------
Reporter: ilyabo | Owner: scala-xml_team
Type: defect | Status: closed
Priority: normal | Component: XML support
Version: | Resolution: fixed
Keywords: XML |
-------------------+--------------------------------------------------------
Changes (by extempore):
* status: new => closed
* resolution: => fixed
Comment:
(In [23319]) Fix involving xml equality, contributed by mark harrah.
Closes #3886, no review.
-------------------+--------------------------------------------------------
Reporter: ilyabo | Owner: scala-xml_team
Type: defect | Status: new
Priority: normal | Component: XML support
Keywords: XML |
-------------------+--------------------------------------------------------
Changes (by harrah):
* cc: harrah@… (added)
Comment:
Simpler test case:
{{{
scala> ==
res0: true
}}}
The issue is the implementation of `strict_==` for `Attribute`. It
overrides the definition of `MetaData` but does not recurse. So, only the
first attribute is compared. As far as I can tell, `MetaData.strict_==`
is never called.
Patch attached that removes `MetaData.strict_==` and adds `&& (next ==
x.next)` to `Attribute.strict_==`. Also attached is a test case for
`test/files/run`.