Use toVector for XML literal sequences#23221
Merged
Merged
Conversation
toVector` for XML literal sequencestoVector for XML literal sequences
Member
Author
|
I have a related PR to scala-xml which changes the API to return The current $ scala repl -S 3 --dep org.scala-lang.modules::scala-xml:2.3.0
scala> import scala.xml._
scala> val x: collection.immutable.Seq[Node] = <a><b/></a>
val x: Seq[scala.xml.Node] = <a><b/></a>
scala> x.asInstanceOf[scala.xml.Node].child.asInstanceOf[scala.xml.NodeSeq].theSeq.asInstanceOf[NodeBuffer] += <c/>
scala> x
val res1: Seq[scala.xml.Node] = <a><b/><c/></a> |
0112edf to
ebdd2f5
Compare
Member
Author
|
There is code that relies on XML sequences
Method I narrowed the change so that plain XML sequences keep type |
Contributor
|
I know you have your reasons. But the dust you raise makes me sneeze. Oh it almost rhymes. |
SethTisue
approved these changes
Aug 8, 2025
Member
|
@lrytz rebase? |
In `<a><b/><c/><a>`, a `NodeBuffer` (which extends `ArrayBuffer`) is
used to accumulate the children. The buffer is passed to
`new Elem($buf: _*)`, which only works thanks to the implicit
`collection.Seq[Node] => NodeSeq` declared in scala-xml.
With `-Vprint:typer`:
```scala
scala> <a><b/></a>
[[syntax trees at end of typer]] // rs$line$1
val res0: scala.xml.Elem =
{
new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null,
scala.xml.TopScope, false,
{
val $buf: scala.xml.NodeBuffer = new _root_.scala.xml.NodeBuffer()
$buf.&+(
{
{
new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null,
scala.xml.TopScope, true, [ : scala.xml.Node]*)
}
}
)
scala.xml.NodeSeq.seqToNodeSeq($buf)
}*
)
}
```
The implicit was not inserted in 2.12 because the varargs parameter of
Elem accepted a `collection.Seq`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Forward-port of scala/scala#11065
In
<a><b/><c/><a>, aNodeBuffer(which extendsArrayBuffer) is used to accumulate the children. The buffer is passed tonew Elem($buf: _*), which only works thanks to the implicitcollection.Seq[Node] => NodeSeqdeclared in scala-xml.With
-Vprint:typer:The implicit was not inserted in 2.12 because the varargs parameter of Elem accepted a
collection.Seq.