Skip to content

Commit

Permalink
Extend diagnostics only in the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Oct 30, 2024
1 parent 108be51 commit b50d38c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/red_knot_python_semantic/src/types/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ impl<'db> TypeCheckDiagnosticsBuilder<'db> {
});
}

pub(super) fn extend(&mut self, diagnostics: &TypeCheckDiagnostics) {
self.diagnostics.extend(diagnostics);
}

pub(super) fn finish(mut self) -> TypeCheckDiagnostics {
self.diagnostics.shrink_to_fit();
self.diagnostics
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<'db> TypeInferenceBuilder<'db> {
.declarations
.extend(inference.declarations.iter());
self.types.expressions.extend(inference.expressions.iter());
self.types.diagnostics.extend(&inference.diagnostics);
self.diagnostics.extend(&inference.diagnostics);
self.types.has_deferred |= inference.has_deferred;
}

Expand Down Expand Up @@ -3472,7 +3472,7 @@ impl<'db> TypeInferenceBuilder<'db> {

pub(super) fn finish(mut self) -> TypeInference<'db> {
self.infer_region();
self.types.diagnostics.extend(self.diagnostics.finish());
self.types.diagnostics = self.diagnostics.finish();
self.types.shrink_to_fit();
self.types
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_benchmark/benches/red_knot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ static EXPECTED_DIAGNOSTICS: &[&str] = &[
"/src/tomllib/_parser.py:7:29: Module `collections.abc` has no member `Iterable`",
// We don't support terminal statements in control flow yet:
"/src/tomllib/_parser.py:66:18: Name `s` used when possibly not defined",
"/src/tomllib/_parser.py:108:17: Conflicting declared types for `second_char`: Unknown, str | None",
"/src/tomllib/_parser.py:98:12: Name `char` used when possibly not defined",
"/src/tomllib/_parser.py:101:12: Name `char` used when possibly not defined",
"/src/tomllib/_parser.py:104:14: Name `char` used when possibly not defined",
"/src/tomllib/_parser.py:108:17: Conflicting declared types for `second_char`: Unknown, str | None",
"/src/tomllib/_parser.py:115:14: Name `char` used when possibly not defined",
"/src/tomllib/_parser.py:126:12: Name `char` used when possibly not defined",
"/src/tomllib/_parser.py:267:9: Conflicting declared types for `char`: Unknown, str | None",
Expand Down

0 comments on commit b50d38c

Please sign in to comment.