Use toVector for XML literal sequences#11065
Merged
Merged
Conversation
Member
Author
|
I went for |
Member
Author
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]] // <console>
private[this] val res0: scala.xml.Elem = new scala.xml.Elem(null, "a", scala.xml.Null, scala.xml.TopScope, false, (xml.this.NodeSeq.seqToNodeSeq({
val $buf: scala.xml.NodeBuffer = new scala.xml.NodeBuffer();
$buf.&+(new scala.xml.Elem(null, "b", scala.xml.Null, scala.xml.TopScope, true));
$buf
}): _*));
```
The implicit was not inserted in 2.12 because the varargs parameter of
Elem accepted a `collection.Seq`.
SethTisue
approved these changes
Aug 8, 2025
Member
|
eligible for forward-port to Scala 3? |
Member
Author
|
That's already done: scala/scala3#23221 |
SethTisue
added a commit
to scala/scala3
that referenced
this pull request
Jan 19, 2026
Forward-port of scala/scala#11065 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.

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.This PR changes the compiler translation to use
toVector.Note that there was a related change in scala-xml 2.4.0 to use
immutable.Seqinstead ofcollection.Seqfor core parts of the scala-xml API (https://github.com/scala/scala-xml/releases/tag/v2.4.0).