Repository navigation
SA1100: avoid unsafe virtual dispatch fixes - #4273
Merged
Merged
Conversation
Keep the diagnostic, but withhold individual and Fix All changes for overridable members in inheritable types. Preserve safe fixes for sealed members and receiver types. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The safety guard is correctly scoped to code fixes and has comprehensive regression coverage.
0 open findings
What changed in this PR
Prevents SA1100 code fixes from changing virtual dispatch while preserving the diagnostic.
Changes:
- Adds semantic safety checks for individual and Fix All operations.
- Expands regression coverage across member kinds and inheritance scenarios.
- Documents the limitation in English, Russian, and Czech.
| File | Description |
|---|---|
test/StyleCop.Analyzers.Test/ReadabilityRules/SA1100UnitTests.cs |
Adds comprehensive safety and Fix All tests. |
test/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1100CSharp9UnitTests.cs |
Updates covariant-override expectations. |
src/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1100CodeFixProvider.cs |
Withholds unsafe virtual-dispatch fixes. |
documentation/SA1100.md |
Documents code-fix limitations. |
documentation/ru-ru/SA1100.md |
Adds Russian documentation. |
documentation/cs-cz/SA1100.md |
Adds Czech documentation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4273 +/- ##
==========================================
- Coverage 97.61% 97.61% -0.01%
==========================================
Files 1285 1285
Lines 137307 137241 -66
Branches 4451 4467 +16
==========================================
- Hits 134029 133962 -67
Misses 2113 2113
- Partials 1165 1166 +1 🚀 New features to boost your workflow:
|
This was referenced Nov 11, 2026
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/aspnetcore-webhooks-sample#436
Open
Closed
Open
This was referenced Nov 20, 2026
[DPDBT] Bump Microsoft.CodeAnalysis.Analyzers and 6 others
sergey-rybalkin/CommandLine.Generators#63
Open
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.
Fixes #2938
Changing
base.DoSomething()tothis.DoSomething()in an intermediate class can dispatch to a subclass override and recurse through the intermediate helper until stack overflow. The diagnostic is valid, but this change is not safe to apply automatically.The analyzer is unchanged. The code fix now withholds both individual fixes and Fix All replacements for overridable members in inheritable receiver types. Non-virtual members, sealed overrides, and calls in sealed receiver types retain their automatic fixes. The same guard covers methods, properties, indexers, and events. English, Russian, and Czech rule documentation describe the limitation.
Regression evidence:
TestSubclassOverrideCallsIntermediateHelperAsyncwas added before any product change and failed against master5fb0ffaf999434bf5b78b7c8bb86c8334ac46b37. The verifier showed the exact unsafe diff: expectedbase.DoSomething(), actualthis.DoSomething(). It now passes while retaining the SA1100 diagnostic. Existing virtual-call code-fix expectations now explicitly require unchanged source and the same diagnostics; none of these tests were skipped or disabled.Additional coverage exercises inherited overrides, sealed members and receiver types, property/indexer getters and setters, event add/remove, and mixed Fix All operations with comments and an unsafe-only second document. Method-group cases verify the analyzer's existing behavior remains unchanged.
Validation with SDK 10.0.401:
dotnet build -c Release -maxcpucount:1 --verbosity quiet: succeeded, 0 warnings and 0 errors.net10.0in all C# 6–15 test projects: 662 passed, 0 failed, 0 skipped (63 in the lowest project; 68 in C# 15).git diff --check: clean.Performance: no analyzer changes or analysis-time cost. Semantic safety checks run only in the code fix, reusing one semantic model per registration/document. Shipped Roslyn dependency pins are unchanged.
This PR remains a draft for CI and human review.