diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2017-03-13 23:48:08 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2017-03-14 14:16:09 +0100 |
commit | 961201e1f6d8f9efa19f88ddc1204a0f20aaab1c (patch) | |
tree | 9140070e42297e0156e9dd8614ae93c4a676cd42 /sbt-bridge | |
parent | c7acb7bbb296237dc56ea8d124d6ad4a8dbb7003 (diff) | |
download | dotty-961201e1f6d8f9efa19f88ddc1204a0f20aaab1c.tar.gz dotty-961201e1f6d8f9efa19f88ddc1204a0f20aaab1c.tar.bz2 dotty-961201e1f6d8f9efa19f88ddc1204a0f20aaab1c.zip |
sbt-bridge: Don't crash when a Message does not have a Position
Diffstat (limited to 'sbt-bridge')
-rw-r--r-- | sbt-bridge/src/xsbt/DelegatingReporter.scala | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/sbt-bridge/src/xsbt/DelegatingReporter.scala b/sbt-bridge/src/xsbt/DelegatingReporter.scala index e704a29c9..17a52feaa 100644 --- a/sbt-bridge/src/xsbt/DelegatingReporter.scala +++ b/sbt-bridge/src/xsbt/DelegatingReporter.scala @@ -27,15 +27,19 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter case _ => xsbti.Severity.Info } - val position = new Position { - def line: Maybe[Integer] = Maybe.just(cont.pos.line) - def lineContent: String = cont.pos.lineContent - def offset: Maybe[Integer] = Maybe.just(cont.pos.point) - def pointer: Maybe[Integer] = Maybe.just(cont.pos.point) - def pointerSpace: Maybe[String] = Maybe.just(" " * cont.pos.point) - def sourceFile: Maybe[java.io.File] = maybe(Option(cont.pos.source.file.file)) - def sourcePath: Maybe[String] = maybe(Option(cont.pos.source.file.file).map(_.getPath)) - } + val position = + if (cont.pos.exists) + new Position { + val line: Maybe[Integer] = Maybe.just(cont.pos.line) + val lineContent: String = cont.pos.lineContent + val offset: Maybe[Integer] = Maybe.just(cont.pos.point) + val pointer: Maybe[Integer] = Maybe.just(cont.pos.point) + val pointerSpace: Maybe[String] = Maybe.just(" " * cont.pos.point) + val sourceFile: Maybe[java.io.File] = maybe(Option(cont.pos.source.file.file)) + val sourcePath: Maybe[String] = maybe(Option(cont.pos.source.file.file).map(_.getPath)) + } + else + noPosition val sb = new StringBuilder() sb.append(messageAndPos(cont.contained, cont.pos, diagnosticLevel(cont))) @@ -50,4 +54,14 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter case None => Maybe.nothing[T] case Some(s) => Maybe.just[T](s) } + + private[this] val noPosition = new Position { + val line: Maybe[Integer] = Maybe.nothing[Integer] + val lineContent: String = "" + val offset: Maybe[Integer] = Maybe.nothing[Integer] + val pointer: Maybe[Integer] = Maybe.nothing[Integer] + val pointerSpace: Maybe[String] = Maybe.nothing[String] + val sourceFile: Maybe[java.io.File] = Maybe.nothing[java.io.File] + val sourcePath: Maybe[String] = Maybe.nothing[String] + } } |