Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor abstract required during state initialization in nullable #76363

Merged
merged 4 commits into from
Dec 16, 2024

Conversation

333fred
Copy link
Member

@333fred 333fred commented Dec 10, 2024

Fixes #74423. When we're enforcing that all members of a type must have non-null values for SetsRequiredMembers, we don't want to include any members of the current type that are overrides of a base type. Instead, those members should be enforced when we check the chained constructor call, since the chained constructor may itself have SetsRequiredMembers, and therefore already enforced that overridden properties have a valid state.

@333fred 333fred requested a review from a team as a code owner December 10, 2024 23:04
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 10, 2024
@333fred
Copy link
Member Author

333fred commented Dec 10, 2024

@RikkiGibson @dotnet/roslyn-compiler for reviews.

@RikkiGibson RikkiGibson self-assigned this Dec 11, 2024
@RikkiGibson
Copy link
Contributor

Fixes dotnet#74423. When we're getting the list of members to default initialize, we look for properties that override `abstract` properties and have nullable annotations that line up with the base ones. For these properties, we can assume that if we chain to a `SetsRequiredMembers` constructor, it took care of setting a non-null state.
@333fred 333fred changed the title Do not check overridden required members during in-type member enforcement Do honor abstract required during state initialization in nullable Dec 12, 2024
Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

Done review pass, I will need a little more time to soak it all in and to see a few more tests.

@RikkiGibson RikkiGibson self-requested a review December 13, 2024 01:05
Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

I meant to hit approve before, must have misclicked.

@333fred 333fred changed the title Do honor abstract required during state initialization in nullable Honor abstract required during state initialization in nullable Dec 16, 2024
@333fred
Copy link
Member Author

333fred commented Dec 16, 2024

@dotnet/roslyn-compiler for a second review

@AlekseyTs
Copy link
Contributor

@333fred Can you think of any VB scenario affected as well?

@333fred
Copy link
Member Author

333fred commented Dec 16, 2024

@333fred Can you think of any VB scenario affected as well?

VB cannot subclass types with required members, and also does not have NRT, so I do not think it can encounter this issue.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 4)

@333fred 333fred merged commit d6eb229 into dotnet:main Dec 16, 2024
24 checks passed
@333fred 333fred deleted the required-virtuals branch December 16, 2024 22:50
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
3 participants