diff --git a/main/actions/src/main/scala/sbt/compiler/Eval.scala b/main/actions/src/main/scala/sbt/compiler/Eval.scala index e533ac5a2..f41fb9dbe 100644 --- a/main/actions/src/main/scala/sbt/compiler/Eval.scala +++ b/main/actions/src/main/scala/sbt/compiler/Eval.scala @@ -348,8 +348,21 @@ final class Eval(optionsNoncp: Seq[String], classpath: Seq[File], mkReporter: Se val DefaultStartLine = 0 private[this] def makeModuleName(hash: String): String = "$" + Hash.halve(hash) - private[this] def noImports = new EvalImports(Nil, "") - private[this] def mkUnit(srcName: String, firstLine: Int, s: String) = new CompilationUnit(new EvalSourceFile(srcName, firstLine, s)) + private[sbt] def noImports = new EvalImports(Nil, "") + private[sbt] def mkUnit(srcName: String, firstLine: Int, s: String) = new CompilationUnit(new EvalSourceFile(srcName, firstLine, s)) { + // This is overridden as a workaround for #1181/#1501, + // When the compiler reports an error back, the position sometimes comes back with source set to NoSourceFile. + override def error(pos0: Position, msg: String) = { + import scala.reflect.internal.util._ + val pos = pos0 match { + case op: OffsetPosition if op.point >= 0 => + if (op.source eq source) op + else new OffsetPosition(source, op.point) + case _ => pos0 + } + super.error(pos, msg) + } + } private[this] def checkError(label: String) = if (reporter.hasErrors) throw new EvalException(label) private[this] final class EvalSourceFile(name: String, startLine: Int, contents: String) extends BatchSourceFile(name, contents) { diff --git a/notes/0.13.6.md b/notes/0.13.6.md index 22c4a93c0..556fe7530 100644 --- a/notes/0.13.6.md +++ b/notes/0.13.6.md @@ -2,6 +2,7 @@ [856]: https://github.com/sbt/sbt/issues/856 [1036]: https://github.com/sbt/sbt/pull/1036 [1059]: https://github.com/sbt/sbt/issues/1059 + [1181]: https://github.com/sbt/sbt/issues/1181 [1194]: https://github.com/sbt/sbt/issues/1194 [1200]: https://github.com/sbt/sbt/issues/1200 [1213]: https://github.com/sbt/sbt/issues/1213 @@ -96,6 +97,7 @@ - sbt no longer crashes when run in root directory [#1488][1488] by [@jsuereth][@jsuereth] - set no longer removes any `++` scala version setting. [#856][856]/[#1489][1489] by [@jsuereth][@jsuereth] - Fixes `Scope.parseScopedKey`. [#1384][1384] by [@eed3si9n][@eed3si9n] +- Fixes `build.sbt` errors causing `ArrayIndexOutOfBoundsException` due to invalid source in position. [#1181][1181] by [@eed3si9n][@eed3si9n] ### enablePlugins/disablePlugins