scala - Is there a way to use pattern matching in build.sbt? -


i'm trying play scala's playframework , running issue build.sbt file. specifically:

pattern matching in val statements not supported 

which obvious:

val env = sys.props.getorelse("env", default = "local")  val (someval, otherval) = env match {     case "local" => ("x","a")     case _ => //etc } 

is there way use match statement in build.sbt file @ all? error says it's not supported in val statements. supported?


edit:

i've tried adding method build.scala object well, when use plain if statements still same "pattern matching in val statements not supported"

build.scala:

import sbt._ import keys._  object examplebuild extends build {      def getenvdata(env: string) = {         if(env == "local") {             ("c","q")          } else if (env == "other") {             ("b","v")         } else {             ("x","a")         }     }     } 

and updated build.sbt:

val env = sys.props.getorelse("env", default = "local")  val (somevar, othervar) = examplebuild.getenvdata(env) 

but no avail.

the error not caused match statement, this:

val (somevar, othervar) = ... 

which form of pattern matching (on tuples) not supported sbt.

here's relevant comment sbtparser implementation

// check no val (a,b) = foo or val a,b = foo these problematic range positions , whole architecture.


you can work around limitation using case class instead of tuple.

in build.scala

case class envdata(somevar: string, othervar: string)  

in build.sbt

val envdata = env match {     case "local" => envdata("x", "a")     case _ => //etc } 

and use envdata.somevar, envdata.othervar , on.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -