Skip to content

Remove [Experimental] From the BindableProperty Source Generators - #3461

Draft
TheCodeTraveler wants to merge 105 commits into
mainfrom
Remove-Experimental-From-BindableProperty-Source-Generators
Draft

TheCodeTraveler wants to merge 105 commits into
mainfrom
Remove-Experimental-From-BindableProperty-Source-Generators

Conversation

@TheCodeTraveler

@TheCodeTraveler TheCodeTraveler commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description of Change

[BindableProperty] and [AttachedBindableProperty<T>] are no longer experimental. This PR removes [Experimental("MCTEXP001")] from both attributes and fixes the generator bugs we found while testing them. It also adds diagnostics for code the generators can't handle, and an opt-in way to use the generated properties with MAUI's XAML source generator.

Note

Draft: still in progress. It's open early so review can start. Still to do:

  • A final review of the whole branch, and three low-priority findings from the last bug hunt to sort.
  • Every diagnostic message says how to fix the problem, with code fixes where possible, and full unit tests for the analyzers and code fixes.
  • Device test runs on Android, iOS, Mac Catalyst and Windows.
  • Re-running the trim audit and the Sample build on the final commit (the trim audit passed on an earlier commit).

Breaking changes

  • Read-only properties from both generators now default to BindingMode.OneWayToSource, like MAUI's CreateReadOnly and CreateAttachedReadOnly. This includes LazyView.IsLoaded.
  • An initializer with an explicit user-defined cast, such as (ImageSource)"a.png", now goes to the default value creator, like the implicit form. Each instance gets its own value, and XProperty.DefaultValue is default(T).
  • A non-empty array default on an attached property now gives each target its own copy.
  • An attached property on a nullable value type (IsNullable or <int?>) registers typeof(int?) with a null default, and setting null stores null.
  • The generated attached Get{Name} and Set{Name} throw ArgumentNullException for a null bindable. This includes the toolkit's own attached properties on DockLayout, StateContainer, StateView, MultiValidationBehavior, SetFocusOnEntryCompletedBehavior and the Android NavigationBar.
  • A property named with a keyword, such as @event, registers the property name event instead of @event.
  • [Obsolete] and [Experimental] on a property are copied to its generated XProperty field.
  • BindablePropertyDiagnostic.BindablePropertyAttributeExperimentalDiagnosticId (MCTEXP001) is now [Obsolete]. It will be removed in .NET 12.
What else changed

Tests (latest local run)

  • CommunityToolkit.Maui.UnitTests: 12,840 passed, under both the default culture and tr-TR.
  • Source generator unit tests: 1,789 passed. The test host is killed for memory after about 5 minutes on our Mac, so CI is the reference.
  • pwsh eng/format.ps1 is clean, and the library builds for net11.0 with 0 warnings.

Linked Issues

PR Checklist

Additional information

Tested locally on macOS. Device tests are still to come (see the note above).

🤖 Generated with Claude Code

TheCodeTraveler and others added 30 commits November 26, 2026 20:22
… type (r1-11)

Models hold type names instead of ITypeSymbol, outputs are grouped per type after Collect so unchanged types stay cached, and incremental-step tests cover unrelated edits, edits inside a type and symbol-free tracked outputs. The ArrayPool buffers are gone, so there is nothing left to clear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…amed arguments, skips file-local types and static-constructor fields

Adds SG and runtime tests for r1-04, r1-05, r1-06, r1-09, r1-21, r1-22, r2-03, r2-12 and r3-01.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove dead Roslyn setup from BindablePropertyModelTests; the old ITypeSymbol assertions (propertySymbol.Type vs ReturnType, DeclaringType) were replaced because they locked in r1-11.
Add attached constructor and class+constructor merge cases to the caching tests, and named tracking steps for the model providers.
Drop unread AttachedBindablePropertyModel DeclaringTypeName/IsDeclaringTypeNullable; move ShouldPostpendNullableToType into the generator; compute it once; pass method groups to RegisterSourceOutput.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ashing the generators (r1-10, r3-02)

Adds an equatable diagnostic model carried through both pipelines, and test
infrastructure (multi-file driver run, user-file diagnostics, DiagnosticResult
support). Replaces the tests that locked in the old throws with tests that
expect the diagnostics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- r1-09: folded byte/sbyte/short/ushort/nint/nuint constants keep their own type via a cast
- r3-01: file-local enum fold and default(FileLocalStruct) now use the creator instead of naming the type or boxing null
- r1-05: static constructor guard only applies to fields without initializer or that the constructor mentions; replaces the SG test that locked in the broader (17.0.0-changing) behavior
- Brush NotSame checks stay removed: MAUI caches the Color->Brush result, so identity is not the toolkit's to assert
- Shared GeneratedCreateCallLookup test helper, unused DefaultAmount constants removed, stale test comments reworded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Recursive file-local type check (type arguments, arrays, pointers), in arguments kept, static-constructor guard counts only writes, generic nested receiver keeps type arguments, KeywordNamedFieldsHost derives from BindableObject.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…modifier misuse as MCTSG010-022 (r2-07, r2-09, r2-10, r2-11, r1-23, r1-02, r1-03, r3-05, U5, U7, U8)

Replaces two lock-in tests that expected no diagnostic for an initializer next to DefaultValueCreatorMethodName (now an Info).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qualify callbacks imported with using static, report simple-name callbacks on file-local attached hosts, unbound generic qualifiers (MCTSG024) and bodyless or conditional callbacks (MCTSG025).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r helper always nested in the host (r2-02, r2-01, r1-14, U3, U10)

Replaced expected-output tests and the strict-warning ID list that locked in the namespace-level helper and the process-wide static flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l host keyword, support record attached hosts (r1-02, r1-03, r2-05, U6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t attached hosts; format

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy unsafe, skip non-partial record attached hosts with MCTSG026, pin override-of-base-BP and creator-path hazards, tighten host tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, fix read-only attached array typeof, drop @ from PropertyName

Existing snapshot expectations were updated: they locked in unqualified type names and the "@Class" PropertyName (r1-15, DECIDED).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Escape contextual keywords (file, required, scoped) as type names, share the helper with the callback resolver, escape qualified nameof callbacks, derive the keyword test view from BindableObject, and reuse DeclaringTypeName for the helper cast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…able value types, null-checked accessors, XML doc prefix, file-local type diagnostic (r2-08, r1-16, S02, D6, U4/S15, U13)

Updated snapshot tests that locked in typeof(int) for nullable value types and expression-bodied accessors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-06), read-only default OneWayToSource (S05/D4), documented key field (r1-17)

Snapshot tests that locked in BindingMode 0 for read-only properties now expect OneWayToSource.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict in BindablePropertyAttributeSourceGenerator.cs: B0 replaced the
model's ITypeSymbol ReturnType with strings, so B2's r1-04 dynamic fix now
computes the typeof operand ("object" for dynamic) into
NonNullableReturnTypeName and carries a new IsDynamicReturnType bool for the
(object?) setter cast. B4's IsObsolete and AppendInitializingField are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sts, U10 comment in the resolver

B3 qualifies the declaring type in typeof() with global::, so B2's
ResolvedDefaultValueConversionTests now expect
typeof(global::TestNamespace.TestView). The assertions are otherwise unchanged.

Adds the U10 WHY comment that B4's review deferred to the resolver: a host
field from another partial file is read safely only because Roslyn orders
generated trees after user trees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the merge the cast is driven by the new IsDynamicReturnType model
flag. Without it SetValue binds through the C# runtime binder (not trim-safe
or NativeAOT-safe), yet every existing test passed (B2 review 3, nit 1).
Rows for "", tr-TR and az-Latn-AZ, writable and read-only key setters.
With the flag forced to false, exactly these new tests fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheCodeTraveler and others added 26 commits November 28, 2026 08:37
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the field the property's diagnostic, not always a warning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Error-level [Obsolete] on a declared field no longer breaks generated code: the static constructors get a warning-level [Obsolete], and attached accessors read the field through an [Obsolete] helper. Sample member order and a using fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nerated accessors (MCTSG036) and merge same-named file-local hosts safely

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- MCTSG036 says "the generated GetMode method" or "the generated GetMode and SetMode methods" instead of a singular "method" for two accessors.
- The bug theory asserts the quoted least accessible type ('P.Mode', 'P.H.Secret', 'P.Modes.Mode') and the full accessor and setting phrase, so naming List<Mode> or Mode[] instead of Mode fails.
- New bug rows: an array of an internal enum, and a protected internal getter with an internal type (both CS0050 on origin/main).
- Renames: accessorsMoreAccessibleThanTheType, EffectiveAccessibility.GetForTypeAndContainers and GetForTypeIncludingTypeArguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bleProperty] declarations so CS9248 no longer hides the MCTSG analyzer diagnostics on command-line builds (r4-01)

Replaces the three EdgeCase tests that expected CS9248 next to the MCTSG005 (they locked in the bug).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ect (MCTSG037), a property type that cannot be stored as object (MCTSG038) and a non-field member named like the property field (MCTSG030) on the user's code (r4-02, r4-12, r4-07)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…essors of a skipped attached property so CS8795 no longer hides the MCTSG diagnostics (r4-01, attached part)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the field-backed stub body only under C# 14, make the MCTSG037 message one sentence, pin ID, severity and line in the new diagnostic tests, add skipped-with-initializer command-line rows, and tidy the stub helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SG039, not as missing (r4-13)

The old OtherCallbacks.Hidden row in MisuseDiagnosticTests locked in the misleading MCTSG010 classification, so it now expects MCTSG039.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…0.0 (r4-03)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…default is read before it is assigned (r4-04, r4-08)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-global usings, and report the ones that cannot be reached (r4-10)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng types

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ons, report unreachable ones as MCTSG040

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…CTSG041

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…G011/MCTSG012, not as missing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheCodeTraveler and others added 2 commits November 29, 2026 14:42
…moving the pragma lines

Windows CI checks the file out with CRLF (* text=auto), so the "...\n" replacements never matched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This label is used for PRs that include a breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant