Disable pattern matching in val syntax in sbt 0.13.7.

Fixes #1661 or at least works around it for now.
This commit is contained in:
Josh Suereth 2014-10-10 13:47:02 -04:00
parent e8b91e4e7e
commit ddf8a173b0
5 changed files with 26 additions and 0 deletions

View File

@ -92,6 +92,21 @@ private[sbt] case class SbtParser(file: File, lines: Seq[String]) extends Parsed
Seq(t)
}
// Check No val (a,b) = foo *or* val a,b = foo as these are problematic to range positions and the WHOLE architecture.
def isBadValDef(t: Tree): Boolean =
t match {
case (x @ (toolbox.u.ValDef(_, _, _, _) | toolbox.u.DefDef(_, _, _, _, _, _))) =>
val content = modifiedContent.substring(x.pos.start, x.pos.end)
val prettyPrint = x.toString
(!(content contains "=") && (prettyPrint contains "="))
case _ => false
}
parsedTrees.filter(isBadValDef).foreach { badTree =>
// Issue errors
val positionLine = badTree.pos.line
throw new MessageOnlyException(s"""[$fileName]:$positionLine: Pattern matching in val statements is not supported""".stripMargin)
}
val (imports, statements) = parsedTrees partition {
case _: Import => true
case _ => false

View File

@ -0,0 +1 @@
val a,b = project

View File

@ -0,0 +1,5 @@
val x = bar
{
val a,b = project
}

View File

@ -134,6 +134,7 @@ abstract class AbstractSplitExpressionsFilesTest(pathName: String) extends Speci
println(s"In file: $fileName, old splitter failed. ${ex.toString}")
case SplitterComparison(_, util.Failure(ex)) =>
println(s"In file: $fileName, new splitter failed. ${ex.toString}")
ex.printStackTrace()
case SplitterComparison(util.Success(resultOld), util.Success(resultNew)) =>
if (resultOld == resultNew) {
println(s"In file: $fileName, same results (imports, settings): $resultOld")

View File

@ -1,3 +1,5 @@
lazy val a,b = project
def now = System.currentTimeMillis
lazy val v = "1.0-" +
@ -10,3 +12,5 @@ val descr = "Description"
name := n
version := v