I am using scala-async with the -xasync compiler option. See the issue there as well: https://github.com/scala/scala-async/issues/316. Using this library (which uses markForAsyncTransform under the hoods) gives false warnings with the rather new scalac-option -Wnonunit-statement.
Reproduction steps
Scala version: 2.13.9
This is an example with scala-async that will trigger the warning (I do not know how to reproduce without a library):
I am using scala-async with the
-xasync
compiler option. See the issue there as well: https://github.com/scala/scala-async/issues/316. Using this library (which usesmarkForAsyncTransform
under the hoods) gives false warnings with the rather new scalac-option-Wnonunit-statement
.Reproduction steps
Scala version: 2.13.9
This is an example with scala-async that will trigger the warning (I do not know how to reproduce without a library):
This will yield a warning:
The generated/desugared code from the scala-async macro involving
markForAsyncTransform
looks like this:The body of the above
apply
method ignores the Boolean value that is returned in the first line.Problem
The code generated by the
markForAsyncTransform
method (see https://github.com/scala/scala/blob/2bd33021228e0dc916f34480bdbe07bbcee3f41d/src/compiler/scala/tools/nsc/transform/async/AsyncPhase.scala#L42) will generate a call toscala.PreDef.locally
which actually returns a value, but that value is ignored. Therefore the scalac-option-Wnonunit-statement
will render a warning. If we would add a: Unit
ascription to that statement, it should pass without warnings.