Skip to content

Commit 3d7cbe2

Browse files
authored
Fix ast-plus errors not failing the build (#1829)
1 parent d8b5228 commit 3d7cbe2

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/java/io/bazel/rulesscala/scalac/deps_tracking_reporter/after_2_12_13_and_before_2_13_12/DepsTrackingReporter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ public void prepareReport() throws IOException {
176176

177177
writeSdepsFile(usedDeps, unusedDeps);
178178

179-
Reporter reporter = this.delegateReporter != null ? this.delegateReporter : this;
180-
reportDeps(usedDeps, unusedDeps, reporter);
179+
// Report through `this` so the synthesized strict-deps / unused-deps
180+
// errors increment the wrapper's error count that ScalacInvoker checks
181+
// via `hasErrors()`. Our `doReport` override still forwards each
182+
// diagnostic to `delegateReporter` for display.
183+
reportDeps(usedDeps, unusedDeps, this);
181184
}
182185

183186
private Dependency buildDependency(String jar, String target, Kind kind, boolean ignored) {

src/java/io/bazel/rulesscala/scalac/deps_tracking_reporter/after_2_13_12/DepsTrackingReporter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ public void prepareReport() throws IOException {
167167

168168
writeSdepsFile(usedDeps, unusedDeps);
169169

170-
Reporter reporter = this.delegateReporter != null ? this.delegateReporter : this;
171-
reportDeps(usedDeps, unusedDeps, reporter);
170+
// Report through `this` so the synthesized strict-deps / unused-deps
171+
// errors increment the wrapper's error count that ScalacInvoker checks
172+
// via `hasErrors()`. Our `doReport` override still forwards each
173+
// diagnostic to `delegateReporter` for display.
174+
reportDeps(usedDeps, unusedDeps, this);
172175
}
173176

174177
private Dependency buildDependency(String jar, String target, Kind kind, boolean ignored) {

src/java/io/bazel/rulesscala/scalac/deps_tracking_reporter/before_2_12_13/DepsTrackingReporter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ public void prepareReport() throws IOException {
163163

164164
writeSdepsFile(usedDeps, unusedDeps);
165165

166-
Reporter reporter = this.delegateReporter != null ? this.delegateReporter : this;
167-
reportDeps(usedDeps, unusedDeps, reporter);
166+
// Report through `this` so the synthesized strict-deps / unused-deps
167+
// errors increment the wrapper's error count that ScalacInvoker checks
168+
// via `hasErrors()`. Our `info0` override still forwards each
169+
// diagnostic to `delegateReporter` for display.
170+
reportDeps(usedDeps, unusedDeps, this);
168171
}
169172

170173
private Dependency buildDependency(String jar, String target, Kind kind, boolean ignored) {

src/java/io/bazel/rulesscala/scalac/deps_tracking_reporter/scala_3/DepsTrackingReporter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@ public void prepareReport(Contexts.Context ctx) throws IOException {
160160

161161
writeSdepsFile(usedDeps, unusedDeps);
162162

163-
Reporter reporter = this.delegateReporter != null ? this.delegateReporter : this;
164-
reportDeps(usedDeps, unusedDeps, reporter, ctx);
163+
// Report through `this` so the synthesized strict-deps / unused-deps
164+
// errors increment the wrapper's error count that ScalacInvoker checks
165+
// via `hasErrors()`. Our `doReport` override still forwards each
166+
// diagnostic to `delegateReporter` for display.
167+
reportDeps(usedDeps, unusedDeps, this, ctx);
165168
}
166169

167170
private Dependency buildDependency(String jar, String target, Kind kind, boolean ignored) {

test/shell/test_compiler_dependency_tracking.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ test_fails_for_unused_dep() {
1212
build --extra_toolchains="//test_expect_failure/compiler_dependency_tracker:ast_plus_error" //test_expect_failure/compiler_dependency_tracker:unused_dep
1313
}
1414

15+
# Scala 3 variant of test_fails_for_unused_dep. Catches the bug where the
16+
# Scala 3 DepsTrackingReporter routed synthesized errors to its delegate
17+
# only, so `hasErrors()` stayed false and the build succeeded despite
18+
# printing the error.
19+
test_scala_3_fails_for_unused_dep() {
20+
action_should_fail_with_message \
21+
"buildozer 'remove deps //test_expect_failure/compiler_dependency_tracker:E' //test_expect_failure/compiler_dependency_tracker:unused_dep" \
22+
build --repo_env=SCALA_VERSION=3.8.3 --extra_toolchains="//test_expect_failure/compiler_dependency_tracker:ast_plus_error" //test_expect_failure/compiler_dependency_tracker:unused_dep
23+
}
24+
1525
test_fails_for_missing_compile_dep() {
1626
action_should_fail_with_message \
1727
"buildozer 'add deps //test_expect_failure/compiler_dependency_tracker:E' //test_expect_failure/compiler_dependency_tracker:missing_compile_dep" \
@@ -77,6 +87,7 @@ test_scala_3_given_import_breaks_when_dep_removed() {
7787

7888

7989
$runner test_fails_for_unused_dep
90+
$runner test_scala_3_fails_for_unused_dep
8091
$runner test_fails_for_missing_compile_dep
8192
$runner test_fails_for_strict_dep
8293
$runner test_sdeps

0 commit comments

Comments
 (0)