Repository navigation
Update SA1500 and SA1513 for property initializers after accessor lists (C# 14 field-backed properties) - #4118
Merged
Merged
Conversation
This resolves NU1605 package downgrade errors.
AArnott
force-pushed
the
csharp14-field-property-initializer
branch
2 times, most recently
from
October 7, 2026 03:45
06d6065 to
17bcc2c
Compare
Merge Edwin Engelen's original commits from #4077 (b0af9b7, 0d3e41c, e65f52d, 9b946ab) on top of the C# 14 test project from #4117. Conflict resolution: - b0af9b7 is Edwin's copy of Björn's "Add test project for c# 14" (ccb81f4, already in history). Keep the #4117 version of the C# 14 test project (csproj and SA1107 tests); its Azure Pipelines edits are dropped because master deleted build/build-and-test.yml and build/test.yml (#4105). - SA1500CSharp14UnitTests.cs, SA1513CSharp14UnitTests.cs: take Edwin's tests on top of the empty C# 14 test classes. - The NuGet.Frameworks 6.3.3 -> 6.3.4 bump (0d3e41c) merges cleanly and is kept: it is a patch-level bump of a test-only dependency.
Auto-property initializers after a multi-line accessor list have been valid since C# 6, and SA1500/SA1513 reported them before this change. Put the regression tests in the C# 6 test classes so every language version runs them.
…eld accessor Only allow '=' after a closing brace when the brace closes an accessor list, which matches the SA1513 check. Also add a C# 14 test where a field-backed property has a multi-line accessor body followed by an initializer. Adapted from bjornhellander/NewStyleCopAnalyzers 9afd3de13 and 40995f2f2. Co-authored-by: Björn Hellander <bjorn.hellander@gmail.com>
AArnott
force-pushed
the
csharp14-field-property-initializer
branch
from
October 7, 2026 03:49
17bcc2c to
c01a6ff
Compare
AArnott
marked this pull request as ready for review
October 7, 2026 14:13
This was referenced Oct 8, 2026
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 SA1500 and SA1513 false positives when a property initializer follows the closing brace of a multi-line accessor list. This is common with C# 14 field-backed properties:
This builds on #4077 by @EdwinEngelen: his original commits are merged in unchanged (same SHAs and authorship). It also folds in @bjornhellander's equivalent fix from his fork (bjornhellander/NewStyleCopAnalyzers
9afd3de13,40995f2f2), credited withCo-authored-by.Commits
b0af9b7ed): Edwin's copy of Björn's commit, which Add test project for C# 14 #4117 already has. The merge resolves it to the Add test project for C# 14 #4117 version of the C# 14 test project.0d3e41c6c)e65f52d1f)9b946abd9){ get; set; } = 1;spread over several lines), which has been valid since C# 6. Per the per-language-version pattern, the regression tests go in the C# 6 test classes (SA1500UnitTests,SA1513UnitTests), so all later versions inherit them. Before the fix these tests fail with 2 diagnostics each; after it they pass.=after any closing brace. This commit limits it to a brace that closes an accessor list (case SyntaxKind.EqualsToken when token.Parent.IsKind(SyntaxKind.AccessorList)), the same check SA1513 uses. It also adds Björn's C# 14 test with a multi-linefieldaccessor body.The
NuGet.Frameworks6.3.3 → 6.3.4 bump inTest.CSharp8from #4077 is kept. It's a harmless patch-level bump of a test-only dependency, and keeping it means Edwin's commit doesn't need a revert.Validation
Test.CSharp14runs 8746 tests (8740 + 6 new) and the 6 new tests pass. The failing set matches the Add test project for C# 14 #4117 baseline exactly (known CRLF/LF artifacts). Windows CI is the real gate.Part of #4028 (field-backed properties, under #4046). This doesn't close #4028: the rest of that audit still needs a pass over the other rules.
Supersedes #4077.