mirror of https://github.com/sbt/sbt.git
Merge pull request #3351 from Duhemm/wip/fix-3299
Allow `.value` on SettingKey inside ifs & lambdas
This commit is contained in:
commit
d6803f0645
|
|
@ -1,5 +1,6 @@
|
||||||
package sbt.std
|
package sbt.std
|
||||||
|
|
||||||
|
import sbt.SettingKey
|
||||||
import sbt.internal.util.ConsoleAppender
|
import sbt.internal.util.ConsoleAppender
|
||||||
import sbt.internal.util.appmacro.{ Convert, Converted, LinterDSL }
|
import sbt.internal.util.appmacro.{ Convert, Converted, LinterDSL }
|
||||||
|
|
||||||
|
|
@ -62,10 +63,12 @@ abstract class BaseTaskLinterDSL extends LinterDSL {
|
||||||
case ap @ Apply(TypeApply(Select(_, nme), tpe :: Nil), qual :: Nil) =>
|
case ap @ Apply(TypeApply(Select(_, nme), tpe :: Nil), qual :: Nil) =>
|
||||||
val shouldIgnore = uncheckedWrappers.contains(ap)
|
val shouldIgnore = uncheckedWrappers.contains(ap)
|
||||||
val wrapperName = nme.decodedName.toString
|
val wrapperName = nme.decodedName.toString
|
||||||
if (!shouldIgnore && isTask(wrapperName, tpe.tpe, qual)) {
|
val (qualName, isSettingKey) =
|
||||||
val qualName =
|
Option(qual.symbol)
|
||||||
if (qual.symbol != null) qual.symbol.name.decodedName.toString
|
.map(sym => (sym.name.decodedName.toString, sym.info <:< typeOf[SettingKey[_]]))
|
||||||
else ap.pos.lineContent
|
.getOrElse((ap.pos.lineContent, false))
|
||||||
|
|
||||||
|
if (!isSettingKey && !shouldIgnore && isTask(wrapperName, tpe.tpe, qual)) {
|
||||||
if (insideIf && !isDynamicTask) {
|
if (insideIf && !isDynamicTask) {
|
||||||
// Error on the use of value inside the if of a regular task (dyn task is ok)
|
// Error on the use of value inside the if of a regular task (dyn task is ok)
|
||||||
ctx.error(ap.pos, TaskLinterDSLFeedback.useOfValueInsideIfExpression(qualName))
|
ctx.error(ap.pos, TaskLinterDSLFeedback.useOfValueInsideIfExpression(qualName))
|
||||||
|
|
|
||||||
|
|
@ -150,4 +150,25 @@ class TaskPosSpec {
|
||||||
avoidDCE
|
avoidDCE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locally {
|
||||||
|
import sbt._
|
||||||
|
import sbt.Def._
|
||||||
|
val foo = settingKey[String]("")
|
||||||
|
val condition = true
|
||||||
|
val baz = Def.task[String] {
|
||||||
|
// settings can be evaluated in a condition
|
||||||
|
if (condition) foo.value
|
||||||
|
else "..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locally {
|
||||||
|
import sbt._
|
||||||
|
import sbt.Def._
|
||||||
|
val foo = settingKey[String]("")
|
||||||
|
val baz = Def.task[Seq[String]] {
|
||||||
|
(1 to 10).map(_ => foo.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue