Work around "a pure expression does nothing" warning, take 2

In https://github.com/sbt/sbt/pull/5981 I tried to work around the spruious post-macro "a pure expression does nothing" warning (https://github.com/scala/bug/issues/12112) by trying to remove some pure-looking expressions out of the tree.

This quickly backfired when it was reported that sbt 1.4.3 was not evaluating some code. This backs out the macro-level manipulation, and instead try to silence the warning at the reporter level. This feels safer, and it seems to work just as well.
This commit is contained in:
Eugene Yokota 2020-11-22 16:19:27 -05:00
parent 07f347b0f4
commit 00265bf912
3 changed files with 12 additions and 5 deletions

View File

@ -187,9 +187,7 @@ object Instance {
qual.foreach(checkQual)
val vd = util.freshValDef(tpe, qual.pos, functionSym)
inputs ::= new Input(tpe, qual, vd)
// try to workaround https://github.com/scala/bug/issues/12112 by calling Predef.identity(...)
val rv = util.refVal(selection, vd)
q"scala.Predef.identity[$tpe]($rv: $tpe)"
util.refVal(selection, vd)
}
def sub(name: String, tpe: Type, qual: Tree, replace: Tree): Converted[c.type] = {
val tag = c.WeakTypeTag[T](tpe)

View File

@ -204,10 +204,11 @@ object BuildServerProtocol {
val converter = fileConverter.value
val underlying = (Keys.compile / compilerReporter).value
val logger = streams.value.log
val meta = isMetaBuild.value
if (bspEnabled.value) {
new BuildServerReporterImpl(targetId, converter, logger, underlying)
new BuildServerReporterImpl(targetId, converter, meta, logger, underlying)
} else {
new BuildServerForwarder(logger, underlying)
new BuildServerForwarder(meta, logger, underlying)
}
}
)

View File

@ -28,6 +28,9 @@ import scala.collection.mutable
sealed trait BuildServerReporter extends Reporter {
private final val sigFilesWritten = "[sig files written]"
private final val pureExpression = "a pure expression does nothing in statement position"
protected def isMetaBuild: Boolean
protected def logger: ManagedLogger
@ -52,6 +55,9 @@ sealed trait BuildServerReporter extends Reporter {
override def log(problem: Problem): Unit = {
if (problem.message == sigFilesWritten) {
logger.debug(sigFilesWritten)
} else if (isMetaBuild && problem.message.startsWith(pureExpression)) {
// work around https://github.com/scala/bug/issues/12112 by ignoring it in the reporter
logger.debug(problem.message)
} else {
publishDiagnostic(problem)
underlying.log(problem)
@ -64,6 +70,7 @@ sealed trait BuildServerReporter extends Reporter {
final class BuildServerReporterImpl(
buildTarget: BuildTargetIdentifier,
converter: FileConverter,
protected override val isMetaBuild: Boolean,
protected override val logger: ManagedLogger,
protected override val underlying: Reporter
) extends BuildServerReporter {
@ -159,6 +166,7 @@ final class BuildServerReporterImpl(
}
final class BuildServerForwarder(
protected override val isMetaBuild: Boolean,
protected override val logger: ManagedLogger,
protected override val underlying: Reporter
) extends BuildServerReporter {