From 12c8e1f5700e4d4f148d6e53cc3aaa7c64145b7f Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Wed, 4 Mar 2020 13:00:28 +0100 Subject: [PATCH] Add +1 to zinc positions in the compiler bridge --- sbt-bridge/src/xsbt/DelegatingReporter.java | 2 +- .../simple/project/Reporter.scala | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sbt-bridge/src/xsbt/DelegatingReporter.java b/sbt-bridge/src/xsbt/DelegatingReporter.java index 0f533a0e0d9a..59fd5464bd61 100644 --- a/sbt-bridge/src/xsbt/DelegatingReporter.java +++ b/sbt-bridge/src/xsbt/DelegatingReporter.java @@ -88,7 +88,7 @@ public Optional sourcePath() { else return Optional.ofNullable(src.file().path()); } public Optional line() { - int line = pos.line(); + int line = pos.line() + 1; if (line == -1) return Optional.empty(); else return Optional.of(line); } diff --git a/sbt-dotty/sbt-test/compilerReporter/simple/project/Reporter.scala b/sbt-dotty/sbt-test/compilerReporter/simple/project/Reporter.scala index 1d72caa02cab..46e042cb08b4 100644 --- a/sbt-dotty/sbt-test/compilerReporter/simple/project/Reporter.scala +++ b/sbt-dotty/sbt-test/compilerReporter/simple/project/Reporter.scala @@ -29,9 +29,18 @@ object Reporter { println(problems.toList) assert(problems.size == 1) - // Assert disabled because we don't currently pass positions to sbt - // See https://github.com/lampepfl/dotty/pull/2107 - // assert(problems.forall(_.position.offset.isDefined)) + // make sure position reported by zinc are proper + val mainProblem = problems.head + + val line = mainProblem.position().line() + assert(line.isPresent() == true) + assert(line.get() == 9) + + val pointer = mainProblem.position().pointer() + assert(pointer.isPresent() == true) + assert(pointer.get() == 10) + + assert(problems.forall(_.position.offset.isPresent)) assert(problems.count(_.severity == Severity.Error) == 1) // not found: er1, }).value