Treat init-only custom properties as read-only - #2555
Merged
Manodasan Wignarajah (manodasanW) merged 1 commit intoSep 10, 2026
Merged
Conversation
Preserve readable init-only bindings and add compilation and behavior regression coverage for properties and indexers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sergio Pedri (Sergio0694)
requested a review
from Manodasan Wignarajah (manodasanW)
September 10, 2026 00:32
Manodasan Wignarajah (manodasanW)
approved these changes
Sep 10, 2026
Manodasan Wignarajah (manodasanW)
merged commit Sep 10, 2026
c1d700a
into
staging/3.0
13 checks passed
Manodasan Wignarajah (manodasanW)
deleted the
user/sergiopedri/init-only-binding-support
branch
September 10, 2026 07:08
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
Keep public init-only properties and indexers readable through generated
ICustomPropertyimplementations without reporting them as writable or emitting invalid assignments.Motivation
The custom property provider generator currently classifies any public setter as writable, including
initaccessors. This producesCS8852errors for immutable classes and readonly structs, includingrequiredinit-only properties, and blocks otherwise valid XAML bindings. These members must remain discoverable and readable, with writes rejected just like getter-only members.Changes
src\Authoring\WinRT.SourceGenerator2\CustomPropertyProviderGenerator.Execute.cs: require a public, non-init setter forCanWrite, reusing the existing read-only emission for both properties and indexers.src\Tests\SourceGenerator2Test\Helpers\CSharpGeneratorTest{TGenerator}.cs: add an opt-in helper that checks compilation/emit diagnostics and loads the resulting assembly for behavior assertions, leaving existing snapshot validation unchanged.src\Tests\SourceGenerator2Test\Test_CustomPropertyProviderGenerator.cs: add nine regression cases covering classes, readonly structs, required members, inherited properties, explicit selection, nonpublic setters, and init-only indexers. Assert that initialized values remain readable, init-only writes throwNotSupportedException, and ordinary property/indexer setters remain writable.