Skip to content

Commit

Permalink
refactor: don't forward -1 as the diagnosticCode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ckipp01 committed Dec 12, 2022
1 parent 231f9ab commit 299533d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sbt-bridge/src/dotty/tools/xsbt/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ public Optional<String> rendered() {
}

public Optional<xsbti.DiagnosticCode> 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()));
// We don't forward the code if it's -1 since some tools will assume that this is actually
// the diagnostic code and show it or attempt to use it. This will ensure tools consuming
// this don't all have to be adding checks for -1.
if (_diagnosticCode == "-1") {
return Optional.empty();
} else {
// 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
Expand Down

0 comments on commit 299533d

Please sign in to comment.