Skip to content

Commit 299533d

Browse files
committed
refactor: don't forward -1 as the diagnosticCode
This change ensures that if the diagnostic code is set to -1 that we instead forward None as the code. This will hopefully help any tooling consuming this to not have to add checks for -1 and filter that code out, since it's a useless code.
1 parent 231f9ab commit 299533d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sbt-bridge/src/dotty/tools/xsbt/Problem.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ public Optional<String> rendered() {
4141
}
4242

4343
public Optional<xsbti.DiagnosticCode> diagnosticCode() {
44-
// NOTE: It's important for compatibility that we only construct a
45-
// DiagnosticCode here to maintain compatibility with older versions of
46-
// zinc while using this newer version of the compiler. If we would
47-
// contstruct it earlier, you'd end up with ClassNotFoundExceptions for
48-
// DiagnosticCode.
49-
return Optional.of(new DiagnosticCode(_diagnosticCode, Optional.empty()));
44+
// We don't forward the code if it's -1 since some tools will assume that this is actually
45+
// the diagnostic code and show it or attempt to use it. This will ensure tools consuming
46+
// this don't all have to be adding checks for -1.
47+
if (_diagnosticCode == "-1") {
48+
return Optional.empty();
49+
} else {
50+
// NOTE: It's important for compatibility that we only construct a
51+
// DiagnosticCode here to maintain compatibility with older versions of
52+
// zinc while using this newer version of the compiler. If we would
53+
// contstruct it earlier, you'd end up with ClassNotFoundExceptions for
54+
// DiagnosticCode.
55+
return Optional.of(new DiagnosticCode(_diagnosticCode, Optional.empty()));
56+
}
5057
}
5158

5259
@Override

0 commit comments

Comments
 (0)