You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SA1314: Rename type parameters in documentation crefs - #4361
The SA1314 rename fix updated code references but left generic type-parameter references in documentation cref attributes unchanged. The fix now updates matching references in documentation comments on the declaring type, including partial declarations, while preserving references shadowed by nested or generic method type parameters.
The regression test failed on the original implementation with the reported unchanged cref, and now passes. SA1314 tests pass in the C# 6 and C# 15 test projects. The extra work runs only when applying this code fix and scans documentation comments on the containing type's declarations; no analyzer-path performance impact.
Name and ordinal also match independent placeholders declared by unrelated generic crefs. When fixing Foo<IDENT>, Other{IDENT,TIDENT}.M(IDENT) becomes Other{TIDENT,TIDENT}.M(TIDENT). If Other<TFirst,TSecond> overloads M(TFirst) and M(TSecond), this collapses distinct placeholders and can make the reference ambiguous. The same filter rewrites unrelated generic-method crefs such as M{IDENT,TIDENT}(IDENT,TIDENT). Resolve the generic declaration represented by each cref before selecting its placeholders, rather than matching only name and ordinal. Add regressions for unrelated generic types and methods with these name collisions.
Prevent cref placeholder replacement from capturing source type parameters
This replacement also changes ordinary references bound to the source type parameter before RenameHelper invokes Roslyn's renamer. For Foo<IDENT> with M<T>(IDENT x, T y), a valid cref="M{TIDENT}(IDENT,TIDENT)" becomes M{TIDENT}(TIDENT,TIDENT). The first argument now binds to the cref-local method parameter instead of the enclosing type parameter, so the cref no longer matches M. The later semantic rename sees that already-changed binding. Leave ordinary source-symbol references to the semantic renamer and make the additional placeholder repairs collision-safe. Add a regression for this capture case.
❌ Patch coverage is 97.22222% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (b226ed2) to head (bc40dd9). ⚠️ Report is 8 commits behind head on master.
Rewrite only type arguments in crefs bound to the type being renamed, and cover unrelated cref placeholders, method crefs, and generated partial declarations.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The Codecov report shown here is for an earlier head (1ed73b8), before the subsequent regression-test commits. The latest changes include tests for both reported cases; I reviewed the coverage concern and no additional change is needed based on this stale report.
This also matches constructed types in cref parameter lists. In Foo<IDENT>, a valid cref="Other{IDENT}.M(Foo{IDENT})" can refer to Other<T>.M(Foo<T>); the signature's IDENT then refers to the placeholder declared by Other{IDENT}, not Foo's source type parameter. Rewriting only Foo{IDENT} to Foo{TIDENT} breaks that binding. Exclude parameter-list types from this manual rewrite, leave genuine source-symbol references there to the renamer, and add this regression case.
The new collision check covers sibling type placeholders but excludes generic-method placeholders in the same cref. For Foo<IDENT> containing M<TMethod>(IDENT first, TMethod second), Foo{IDENT}.M{TIDENT}(IDENT,TIDENT) still allows the replacement name TIDENT. This merges the class and method placeholders, so the cref no longer distinguishes the two parameter types and can fail member resolution. Reserve competing placeholder declarations across the entire affected cref, including generic methods and nested types, and add a regression test for this case.
Preserve generic type references in cref parameter lists
Generic type arguments inside a cref parameter list are references, not placeholder declarations. Inside Foo<IDENT>, a cref Other{IDENT}.M(Foo{IDENT}) can refer to Other<T>.M(Foo<T>). This filter changes the inner argument to TIDENT even though it refers to Other's independent placeholder, breaking the member reference. Exclude cref parameter lists from the manual rewrite and let the semantic renamer handle references there. Add a regression test that preserves this cref.
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
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.
Fixes #2966
The SA1314 rename fix updated code references but left generic type-parameter references in documentation
crefattributes unchanged. The fix now updates matching references in documentation comments on the declaring type, including partial declarations, while preserving references shadowed by nested or generic method type parameters.The regression test failed on the original implementation with the reported unchanged
cref, and now passes. SA1314 tests pass in the C# 6 and C# 15 test projects. The extra work runs only when applying this code fix and scans documentation comments on the containing type's declarations; no analyzer-path performance impact.