Skip to content

Fix nullable typeof expressions in custom property providers - #2558

Open
Sergio Pedri (Sergio0694) wants to merge 3 commits into
staging/3.0from
user/sergiopedri/nullable-typeof-generation
Open

Fix nullable typeof expressions in custom property providers#2558
Sergio Pedri (Sergio0694) wants to merge 3 commits into
staging/3.0from
user/sergiopedri/nullable-typeof-generation

Conversation

@Sergio0694

Copy link
Copy Markdown
Member

Summary

Fix GeneratedCustomPropertyProvider emitting nullable reference annotations in typeof expressions for property descriptors and indexer lookup. Retain annotations in casts and preserve nullable value types.

Motivation

Valid nullable binding models currently fail to compile with CS8639 because the generator emits expressions such as typeof(string?) and typeof(object?). Runtime type lookup must omit nullable reference annotations without stripping Nullable<T> or changing init-only setter behavior.

Changes

  • src\Authoring\WinRT.SourceGenerator2\CustomPropertyProviderGenerator.Execute.cs and src\Authoring\WinRT.SourceGenerator2\Models\CustomPropertyInfo.cs: carry separate Roslyn-formatted names for typeof operands alongside the existing nullable-annotated cast names.
  • src\Authoring\WinRT.SourceGenerator2\CustomPropertyProviderGenerator.Emit.cs: use the runtime-type names for ordinary and indexed property descriptors and indexer parameter matching.
  • src\Tests\SourceGenerator2Test\Test_CustomPropertyProviderGenerator.cs: add 18 compilation-based and runtime regression cases covering nullable strings, objects, arrays, generics, structs, and tuples under automatic discovery and explicit selection. Assert descriptor type identity, null round-trips, getter/setter behavior, and read-only init properties.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CsWinRT 3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant