require dynamic initialization to be explicitly enabled for derived settings

This commit is contained in:
Mark Harrah 2013-05-08 12:56:58 -04:00
parent 1b784082a3
commit 60b714e8de
2 changed files with 9 additions and 6 deletions

View File

@ -37,8 +37,8 @@ object Def extends Init[Scope] with TaskMacroExtra
case None => s
}
override def deriveAllowed[T](s: Setting[T]): Option[String] =
super.deriveAllowed(s) orElse
override def deriveAllowed[T](s: Setting[T], allowDynamic: Boolean): Option[String] =
super.deriveAllowed(s, allowDynamic) orElse
(if(s.key.scope != ThisScope) Some(s"Scope cannot be defined for ${definedSettingString(s)}") else None ) orElse
s.dependencies.find(k => k.scope != ThisScope).map(k => s"Scope cannot be defined for dependency ${k.key.label} of ${definedSettingString(s)}")

View File

@ -73,12 +73,15 @@ trait Init[Scope]
def uniform[S,T](inputs: Seq[Initialize[S]])(f: Seq[S] => T): Initialize[T] =
new Apply[({ type l[L[x]] = List[L[S]] })#l, T](f, inputs.toList, AList.seq[S])
def derive[T](s: Setting[T]): Setting[T] = {
deriveAllowed(s) foreach error
/** Constructs a derived setting that will be automatically defined in every scope where one of its dependencies is explicitly defined.
* A setting initialized with dynamic dependencies is only allowed if `allowDynamic` is true.
* Only the static dependencies are tracked, however. */
final def derive[T](s: Setting[T], allowDynamic: Boolean = false): Setting[T] = {
deriveAllowed(s, allowDynamic) foreach error
new DerivedSetting[T](s.key, s.init, s.pos)
}
def deriveAllowed[T](s: Setting[T]): Option[String] = s.init match {
case _: Bind[_,_] => Some("Cannot derive from dynamic dependencies.")
def deriveAllowed[T](s: Setting[T], allowDynamic: Boolean): Option[String] = s.init match {
case _: Bind[_,_] if !allowDynamic => Some("Cannot derive from dynamic dependencies.")
case _ => None
}