mirror of https://github.com/sbt/sbt.git
Fixes #1181/#1501. Fixes ArrayIndexOutOfBoundsException: -1
When the compiler reports back the error to CompilationUnit created by Eval#mkUnit, it sometimes returns OffsetPosition whose `source` is set to `NoSourceFile`. This causes ArrayIndexOutOfBoundsException. The current workaround is to pattern match on the passed in pos and create a new one when the incoming source looks suspicious. I have not figured out whether this is caused by our macro code or compiler. There are various build.sbt errors that would cause this behavior: ```scala libraryDependencies ++= Seq( depA depB // missing comma ) lazy val bob = scala.Console println test ++ run+ ```
This commit is contained in:
parent
0b2f2ae5a8
commit
a9cdd96152
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -93,6 +94,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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue