Skip to content

Commit da50d11

Browse files
authored
refactor: don't forward -1 as the diagnosticCode (#16495)
## Description 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. For example I just hit on this for the first time and saw this: <img width="834" alt="Screenshot 2022-12-10 at 11 48 44" src="https://user-images.githubusercontent.com/13974112/206852283-07c2fa6b-1ad2-4586-860d-d958e4db88ea.png"> Ideally we don't this showing, but if the code is forwarded to the client via LSP like it is in the image, the client has no way to know if -1 is a valid code or not.
2 parents eaff261 + 299533d commit da50d11

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)