scala/scala-async

Async.async gives "nullary-override" warning when not provided with explicit type

shubhamJay opened this issue · 5 comments

val a = async { "hello" } // gives warning 
val b: Future[String] = async { "hello" }

While compiling the above code with compiler option "-Xlint:nullary-override" enabled on scala 2.13.2 version, the first line throws an warning saying nullary method assumes an empty parameter list from the overridden definition. After providing explicit type, the warning goes away as written on second line.

@retronym it came up in the Scala community build that this problem will become more acute with the release of Scala 2.13.3, because @dwijnand's scala/scala#8846 makes this warn by default

https://scala-ci.typesafe.com/job/scala-2.13.x-jdk11-integrate-community-build/1545/artifact/logs/scala-async-build.log

[scala-async] [info] Test scala.async.run.WarningsSpec.noDeadCodeWarningForAsyncThrow started
[scala-async] [error] Test scala.async.run.WarningsSpec.noDeadCodeWarningForAsyncThrow failed: assertion failed: LinkedHashSet(pos: RangePosition(<console>, 109, 115, 136) method without a parameter list overrides a method with a single empty one WARNING, pos: NoPosition No warnings can be incurred under -Werror. ERROR), took 1.47 sec
[scala-async] [info] Test scala.async.run.WarningsSpec.noDeadCodeWarningInMacroExpansion started
[scala-async] [error] Test scala.async.run.WarningsSpec.noDeadCodeWarningInMacroExpansion failed: assertion failed: LinkedHashSet(pos: RangePosition(<console>, 120, 126, 347) method without a parameter list overrides a method with a single empty one WARNING, pos: NoPosition No warnings can be incurred under -Werror. ERROR), took 0.351 sec
[scala-async] [info] Test scala.async.run.WarningsSpec.noPureExpressionInStatementPositionWarning_t74 started
[scala-async] [error] Test scala.async.run.WarningsSpec.noPureExpressionInStatementPositionWarning_t74 failed: scala.tools.reflect.ToolBoxError: reflective compilation has failed:
[scala-async] [error] 
[scala-async] [error] method without a parameter list overrides a method with a single empty one
[scala-async] [error] No warnings can be incurred under -Werror., took 1.354 sec

@shubhamJay as a workaround, I'd suggest using -Wconf to suppress the warning

This problem will go away in scala-async 1.0, which I plan to release in July (once Scala 2.12.12 and 2.12.3 are out.)

scala-ref 2.12.x -cp /Users/jz/code/scala-async/target/scala-2.12/classes -Xasync -Xlint:nullary-override
Welcome to Scala 2.12.12-20200622-114403-72e2d77 (OpenJDK 64-Bit Server VM, Java 1.8.0-adoptopenjdk).
Type in expressions for evaluation. Or try :help.

scala> import scala.concurrent._, ExecutionContext.Implicits.global, scala.async.Async._
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.async.Async._

scala> async { "hello" }
res0: scala.concurrent.Future[String] = Future(Success(hello))

It may also be possible to get rid of the warning in scala-async 0.10.x by tracking down what part of the macro expansion runs afoul of the warning and inserting the parens.

The tree in question is:

override def apply: Unit = apply(null)

This should be def apply() : Unit.

It is generated in

DefDef(NoMods, name.apply, Nil, Nil, TypeTree(definitions.UnitTpe), Apply(Ident(name.apply), literalNull :: Nil))
.

To fix, the vparamss argument should be List(Nil), rather than Nil.

simao commented

Any info on that scala-async 1.x release? I am noticing these warnings with scala 2.13.6. To get rid of the warnings I needed to explicitly set the types return types when using async.

Thanks!