[ty] Show Final source in final assignment diagnostic#24194
Merged
charliermarsh merged 3 commits intomainfrom Mar 26, 2026
Merged
[ty] Show Final source in final assignment diagnostic#24194charliermarsh merged 3 commits intomainfrom
Final source in final assignment diagnostic#24194charliermarsh merged 3 commits intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.59%. The percentage of expected errors that received a diagnostic held steady at 80.96%. The number of fully passing files held steady at 68/132. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 40 | 0 |
invalid-return-type |
0 | 1 | 0 |
| Total | 0 | 41 | 0 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
d95314a to
a44b023
Compare
Final source in final assignment diagnostic
1a2c2af to
a45981b
Compare
a44b023 to
e305f42
Compare
AlexWaygood
approved these changes
Mar 26, 2026
| /// Add a secondary annotation to a diagnostic pointing to the `Final` declaration site. | ||
| fn annotate_final_declaration( | ||
| &self, | ||
| diagnostic: &mut impl DerefMut<Target = Diagnostic>, |
Member
There was a problem hiding this comment.
meh, everything compiles if you just use &mut Diagnostic here
Suggested change
| diagnostic: &mut impl DerefMut<Target = Diagnostic>, | |
| diagnostic: &mut Diagnostic, |
Comment on lines
+51
to
+66
| let class_ty = object_ty | ||
| .nominal_class(db) | ||
| .or_else(|| { | ||
| let Type::TypeVar(typevar) = object_ty else { | ||
| return None; | ||
| }; | ||
|
|
||
| let TypeVarBoundOrConstraints::UpperBound(bound) = | ||
| typevar.typevar(db).bound_or_constraints(db)? | ||
| else { | ||
| return None; | ||
| }; | ||
|
|
||
| bound.nominal_class(db) | ||
| }) | ||
| .or_else(|| object_ty.to_class_type(db))?; |
Member
There was a problem hiding this comment.
should we just add a Type::TypeVar branch to the Type::nominal_class() method rather than special-casing Type::TypeVars here? And also do the same for Type::NewTypeInstance?
Comment on lines
+85
to
+110
| let place_and_quals = | ||
| place_from_declarations(db, use_def.end_of_scope_symbol_declarations(symbol_id)) | ||
| .ignore_conflicting_declarations(); | ||
| if !place_and_quals.qualifiers.contains(TypeQualifiers::FINAL) { | ||
| return None; | ||
| } | ||
|
|
||
| let mut final_declarations = use_def | ||
| .end_of_scope_symbol_declarations(symbol_id) | ||
| .filter_map(|declaration| { | ||
| let DefinitionState::Defined(definition) = declaration.declaration else { | ||
| return None; | ||
| }; | ||
|
|
||
| declaration_type(db, definition) | ||
| .qualifiers() | ||
| .contains(TypeQualifiers::FINAL) | ||
| .then_some(definition) | ||
| }); | ||
| let final_declaration = final_declarations.next()?; | ||
|
|
||
| if final_declarations.next().is_some() { | ||
| return None; | ||
| } | ||
|
|
||
| return Some(final_declaration); |
Member
There was a problem hiding this comment.
you can do this much more simply
Suggested change
| let place_and_quals = | |
| place_from_declarations(db, use_def.end_of_scope_symbol_declarations(symbol_id)) | |
| .ignore_conflicting_declarations(); | |
| if !place_and_quals.qualifiers.contains(TypeQualifiers::FINAL) { | |
| return None; | |
| } | |
| let mut final_declarations = use_def | |
| .end_of_scope_symbol_declarations(symbol_id) | |
| .filter_map(|declaration| { | |
| let DefinitionState::Defined(definition) = declaration.declaration else { | |
| return None; | |
| }; | |
| declaration_type(db, definition) | |
| .qualifiers() | |
| .contains(TypeQualifiers::FINAL) | |
| .then_some(definition) | |
| }); | |
| let final_declaration = final_declarations.next()?; | |
| if final_declarations.next().is_some() { | |
| return None; | |
| } | |
| return Some(final_declaration); | |
| let place_and_quals_result = | |
| place_from_declarations(db, use_def.end_of_scope_symbol_declarations(symbol_id)); | |
| let Some(declaration) = place_and_quals_result.first_declaration else { | |
| continue; | |
| }; | |
| if !place_and_quals_result | |
| .ignore_conflicting_declarations() | |
| .qualifiers | |
| .contains(TypeQualifiers::FINAL) | |
| { | |
| continue; | |
| } | |
| return Some(declaration); |
e305f42 to
a187f90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses a TODO from #23880 to show the
Finalannotation in the final assignment diagnostic.