Skip to content

Change Node.child return type to immutable.Seq on 2.13+ #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lrytz
Copy link
Member

@lrytz lrytz commented May 19, 2025

Change the type of Node.child and Node.nonEmptyChildren from collection.Seq to immutable.Seq in 2.13+.

A parent is added to Node which defines the old signatures for child / nonEmptyChildren. This (and the resulting bridge methods) ensures binary compatbility.

@lrytz lrytz force-pushed the imm-child branch 3 times, most recently from 6436666 to 08e6c71 Compare May 19, 2025 11:46
@lrytz
Copy link
Member Author

lrytz commented May 19, 2025

If we go ahead with this PR we'll need a new minor release (2.4.0).

There is more API with return type collection.Seq that probably always returns an immutable.Seq, e.g.

  • Metadata.value
  • NodeSeq.theSeq
  • MetaData.apply / MetaData.get / Node.attribute
  • TextBuffer.toText
  • BasicTransformer.transform

I'm happy take a look at those as well; I only did child for now because that's what is affecting the 2.13 migration I'm working on.

Change the type of `Node.child` and `Node.nonEmptyChildren` from
`collection.Seq` to `immutable.Seq` in 2.13+.

A parent is added to `Node` which defines the old signatures for
`child` / `nonEmptyChildren`. This (and the resulting bridge methods)
ensures binary compatbility.
@lrytz
Copy link
Member Author

lrytz commented May 19, 2025

For the record, there is an implicit conversion collection.Seq[Node] => NodeSeq and NodeSeq is a subclass of immutable.Seq on 2.13.

So the following works already without this PR

scala> val n: Node = <a><b/></a>
val n: scala.xml.Node = <a><b/></a>

scala> val c: collection.immutable.Seq[Node] = n.child
val c: Seq[scala.xml.Node] = Seq(<b/>)

But this fails:

scala> val c: collection.immutable.Seq[String] = n.child.map(_.toString)
                                                            ^
       error: type mismatch;
        found   : Seq[String] (in scala.collection)
        required: Seq[String] (in scala.collection.immutable)

@retronym retronym self-requested a review May 19, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants