Skip to content

Fix NRT warnings in source generated code - #59755

Merged
eiriktsarpalis merged 3 commits into
dotnet:mainfrom
eiriktsarpalis:fix/sourcegen-nullref-warnings
Sep 30, 2021
Merged

Fix NRT warnings in source generated code#59755
eiriktsarpalis merged 3 commits into
dotnet:mainfrom
eiriktsarpalis:fix/sourcegen-nullref-warnings

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Member

Addresses an issue where STJ source generated code can result in warnings in cases where member types contain nullable reference type annotations. Also updates the annotations for fast-path serialize methods so that the input value type is nullable for the case of reference types.

Note that the implementation intentionally does not take Roslyn nullability metadata into account when inserting suppresions. This is due to a restriction in our current sourcegen infrastructure which abstracts the Roslyn symbols as System.Reflection types: since nullability metadata is not available in that layer it ends up being erased. We should consider changing this in .NET 7.0.0.

Should be considered for 6.0.0 servicing.

Fix#59464.

@eiriktsarpaliseiriktsarpalis added this to the 7.0.0 milestone Sep 29, 2021
@eiriktsarpaliseiriktsarpalis self-assigned this Sep 29, 2021
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Issue Details

Addresses an issue where STJ source generated code can result in warnings in cases where member types contain nullable reference type annotations. Also updates the annotations for fast-path serialize methods so that the input value type is nullable for the case of reference types.

Note that the implementation intentionally does not take Roslyn nullability metadata into account when inserting suppresions. This is due to a restriction in our current sourcegen infrastructure which abstracts the Roslyn symbols as System.Reflection types: since nullability metadata is not available in that layer it ends up being erased. We should consider changing this in .NET 7.0.0.

Should be considered for 6.0.0 servicing.

Fix #59464.

Author:eiriktsarpalis
Assignees:eiriktsarpalis
Labels:

area-System.Text.Json

Milestone:7.0.0

Comment threadsrc/libraries/System.Text.Json/gen/TypeGenerationSpec.cs

@layomialayomia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment threadsrc/libraries/System.Text.Json/gen/Reflection/TypeExtensions.cs Outdated
@eiriktsarpalis
eiriktsarpalis merged commit e581a03 into dotnet:mainSep 30, 2021
@eiriktsarpalis
eiriktsarpalis deleted the fix/sourcegen-nullref-warnings branch September 30, 2021 16:51
@eiriktsarpalis

Copy link
Copy Markdown
MemberAuthor

/backport to release/6.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1291940989

@ghostghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Text.Json source generator produces nullability warnings for NRT properties

4 participants

@eiriktsarpalis@krwq@steveharter@layomia