Skip to content

Special-case nullable walker to understand lock (null) in legacy mode - #85182

Merged
333fred merged 5 commits into
dotnet:mainfrom
DoctorKrolic:lock-over-null
Sep 19, 2026
Merged

333fred merged 5 commits into
dotnet:mainfrom
DoctorKrolic:lock-over-null

Conversation

@DoctorKrolic

@DoctorKrolic DoctorKrolic commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #76597

lock (maybeNullExpr) has already been handled (see test above newly added ones). The only problem was lock (null). It exists only in legacy mode (strict makes it an error), so that null can sneak into runtime and cause ArgumentNullException. It wasn't handled because that null was never assigned a type. Made NullableWalker recognize this case and report it separately

Microsoft Reviewers: Open in CodeFlow

@DoctorKrolic
DoctorKrolic requested a review from a team as a code owner September 6, 2026 17:33
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Sep 6, 2026
@DoctorKrolic DoctorKrolic changed the title Assign null an object type inside lock (null) in legacy mode Special-case nullable walker to understand lock (null) in legacy mode Sep 15, 2026
@DoctorKrolic

Copy link
Copy Markdown
Contributor Author

May I have a review here please?

@RikkiGibson RikkiGibson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM aside from review comment.

I considered if we should use NullableWalker.VisitConversion here, and I think it possibly would have been the best option if we were starting from scratch. But at this point, it doesn't feel worth the churn.

@333fred 333fred left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM other than the unnecessary edits left over in the iop test file.

DoctorKrolic and others added 2 commits September 19, 2026 18:55
Co-authored-by: Rikki Gibson <rikkigibson@gmail.com>
@333fred
333fred enabled auto-merge (squash) September 19, 2026 16:40
@333fred
333fred disabled auto-merge September 19, 2026 16:40
@333fred
333fred enabled auto-merge (squash) September 19, 2026 16:40
@333fred
333fred merged commit fb86547 into dotnet:main Sep 19, 2026
20 of 22 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Sep 19, 2026
@DoctorKrolic
DoctorKrolic deleted the lock-over-null branch September 19, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nullability warning is missing on the lock statement

4 participants