Merge pull request #5981 from eed3si9n/wip/pure-expression

Work around "a pure expression does nothing" warning
This commit is contained in:
eugene yokota 2020-10-19 12:26:41 -04:00 committed by GitHub
commit 8bea523aea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -312,6 +312,17 @@ final class ContextUtil[C <: blackbox.Context](val ctx: C) {
case Converted.Failure(p, m) => ctx.abort(p, m)
case _: Converted.NotApplicable[_] => super.transform(tree)
}
// try to workaround https://github.com/scala/bug/issues/12112 by removing raw Ident(_) in blocks
case Block(stats0, expr0) =>
val stats = stats0 flatMap { stat0 =>
val stat = super.transform(stat0)
stat match {
case Typed(ident @ Ident(_), _) if ident.symbol.isSynthetic => None
case _ => Some(stat)
}
}
val expr = super.transform(expr0)
Block(stats, expr).setType(expr.tpe)
case _ => super.transform(tree)
}
}

View File

@ -0,0 +1,15 @@
package pkgtest
import sbt._, Keys._
// https://github.com/scala/bug/issues/12112
object PureExpressionPlugin extends AutoPlugin {
lazy val testPureExpression = taskKey[Unit]("")
override def projectSettings: Seq[Setting[_]] = {
testPureExpression := {
updateFull.value
(Compile / compile).value
(Test / test).value
}
}
}

View File

@ -0,0 +1 @@
Compile / scalacOptions += "-Xfatal-warnings"