Skip to content

Unused value warnings for XML literals starting with Scala 2.13.9 #650

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

Closed
BennyMcBenBen opened this issue Feb 27, 2023 · 2 comments · Fixed by #744
Closed

Unused value warnings for XML literals starting with Scala 2.13.9 #650

BennyMcBenBen opened this issue Feb 27, 2023 · 2 comments · Fixed by #744

Comments

@BennyMcBenBen
Copy link

If I am using XML literals, then I am seeing compile warnings starting with Scala version 2.13.9. I am using the sbt-tpolecat plugin so these are actually compile errors for me.

Example:

import scala.xml.Elem

case class ToDoItem(name: String) {
  def toXml: Elem = {
    <to-do-item>
      <name>{name}</name>
    </to-do-item>
  }
}

Compile errors:

[error] ToDoItem.scala:5:5: unused value of type scala.xml.NodeBuffer (add `: Unit` to discard silently)
[error]     <to-do-item>
[error]     ^
[error] /ToDoItem.scala:6:7: unused value of type scala.xml.NodeBuffer (add `: Unit` to discard silently)
[error]       <name>{name}</name>

Is this a bug or are the new unused warnings incompatible with XML literals? What do you recommend? Thank you.

@lrytz
Copy link
Member

lrytz commented Feb 28, 2023

The issue here is in the compiler (code it generates for XML literals), not in the xml library. Existing ticket: scala/bug#12658

@lrytz lrytz closed this as completed Feb 28, 2023
@som-snytt
Copy link
Contributor

som-snytt commented Nov 25, 2024

Reopening in order to close it.

Note that under duress, it would be possible to generate different code in the compiler, at the cost of some complexity, but the simple and correct fix is to correct the signature of &+ aka addOne or append for NodeBuffer.

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 a pull request may close this issue.

3 participants