diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 23ee5b7b0427..298c053adf11 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -25,6 +25,6 @@ object Dependencies { "com.vladsch.flexmark" % "flexmark-ext-yaml-front-matter" % flexmarkVersion, ) - val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.4.3" + val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.7.0-M2" val oldCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.3.5" } diff --git a/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java b/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java index 6bf161fafebf..20cdfb720538 100644 --- a/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java +++ b/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java @@ -39,12 +39,13 @@ public void doReport(Diagnostic dia, Context ctx) { StringBuilder rendered = new StringBuilder(); rendered.append(messageAndPos(dia, ctx)); Message message = dia.msg(); + String diagnosticCode = String.valueOf(message.errorId().errorNumber()); boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx); if (shouldExplain && !message.explanation().isEmpty()) { rendered.append(explanation(message, ctx)); } - delegate.log(new Problem(position, message.msg(), severity, rendered.toString())); + delegate.log(new Problem(position, message.msg(), severity, rendered.toString(), diagnosticCode)); } private static Severity severityOf(int level) { diff --git a/sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java b/sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java new file mode 100644 index 000000000000..1a78ce73aa43 --- /dev/null +++ b/sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java @@ -0,0 +1,23 @@ +package dotty.tools.xsbt; + +import java.util.Optional; + +final public class DiagnosticCode implements xsbti.DiagnosticCode { + private final String _code; + private final Optional _explanation; + + public DiagnosticCode(String code, Optional explanation) { + super(); + this._code = code; + this._explanation = explanation; + } + + public String code() { + return _code; + } + + public Optional explanation() { + return _explanation; + } + +} diff --git a/sbt-bridge/src/dotty/tools/xsbt/Problem.java b/sbt-bridge/src/dotty/tools/xsbt/Problem.java index 2f1a7acec00b..30f903b7fa9a 100644 --- a/sbt-bridge/src/dotty/tools/xsbt/Problem.java +++ b/sbt-bridge/src/dotty/tools/xsbt/Problem.java @@ -9,13 +9,15 @@ final public class Problem implements xsbti.Problem { private final String _message; private final Severity _severity; private final Optional _rendered; + private final String _diagnosticCode; - public Problem(Position position, String message, Severity severity, String rendered) { + public Problem(Position position, String message, Severity severity, String rendered, String diagnosticCode) { super(); this._position = position; this._message = message; this._severity = severity; this._rendered = Optional.of(rendered); + this._diagnosticCode = diagnosticCode; } public String category() { @@ -38,6 +40,15 @@ public Optional rendered() { return _rendered; } + public Optional diagnosticCode() { + // NOTE: It's important for compatibility that we only construct a + // DiagnosticCode here to maintain compatibility with older versions of + // zinc while using this newer version of the compiler. If we would + // contstruct it earlier, you'd end up with ClassNotFoundExceptions for + // DiagnosticCode. + return Optional.of(new DiagnosticCode(_diagnosticCode, Optional.empty())); + } + @Override public String toString() { return "Problem(" + _position + ", " + _message + ", " + _severity + ", " + _rendered + ")";