Skip to content

Fatal Warning discarded non-unit value #1816

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
rbscgh opened this issue Feb 7, 2025 · 2 comments · Fixed by #1859
Closed

Fatal Warning discarded non-unit value #1816

rbscgh opened this issue Feb 7, 2025 · 2 comments · Fixed by #1859

Comments

@rbscgh
Copy link

rbscgh commented Feb 7, 2025

Hey folks my projects run with fatal warnings with Wvalue-discard and parseFrom uses builders which produce warning/errors under scala 3 like

[error] 226 |          _unknownFields__.parseField(tag, _input__)
[error]     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |discarded non-Unit value of type scala.collection.mutable.ReusableBuilder[
[error]     |  Long & (com.google.protobuf.ByteString & Int), Vector[Long] | (
[error]     |  Vector[com.google.protobuf.ByteString] | Vector[Int])]

on lines like

        case tag =>
          if (_unknownFields__ == null) {
            _unknownFields__ = new _root_.scalapb.UnknownFieldSet.Builder()
          }
          _unknownFields__.parseField(tag, _input__)

i can silence the error like
scalacOptions ++= Seq("-Wconf:id=175:i,any:v")

but id rather not - anyone else faced this before ?

most likely adding something like

_unknownFields__.parseField(tag, _input__)
() // explicit unit

to the end of these generated builder calls would be the correct fix

@rbscgh rbscgh changed the title Fatal Warning non-discarded value Fatal Warning discarded non-unit value Feb 10, 2025
@rbscgh
Copy link
Author

rbscgh commented Feb 10, 2025

for example here

would need to be updated for all XValue types.. wdyt @thesamet ?

@steinybot
Copy link
Contributor

Another workaround:

            Compile / PB.generate ~= { files =>
                files.filter(_.isFile).foreach { file =>
                    val fileContent = IO.read(file)
                    val updatedContent = fileContent.replace(
                        "_unknownFields__.parseField(tag, _input__)",
                        "_unknownFields__.parseField(tag, _input__): Unit"
                    )
                    IO.write(file, updatedContent)
                }
                files
            },

steinybot added a commit to steinybot/ScalaPB that referenced this issue May 26, 2025
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.

2 participants