Skip to content

Conversation

@eiriktsarpalis
Copy link
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.

@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Sep 29, 2021
@eiriktsarpalis eiriktsarpalis self-assigned this Sep 29, 2021
@ghost
Copy link

ghost commented Sep 29, 2021

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

Copy link
Contributor

@layomia layomia left a comment

Choose a reason for hiding this comment

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

LGTM

@eiriktsarpalis eiriktsarpalis merged commit e581a03 into dotnet:main Sep 30, 2021
@eiriktsarpalis eiriktsarpalis deleted the fix/sourcegen-nullref-warnings branch September 30, 2021 16:51
@eiriktsarpalis
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

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

@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to 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