Skip to content

Fix nullable analysis involving extensions and collection expressions#78926

Merged
RikkiGibson merged 7 commits intodotnet:mainfrom
RikkiGibson:extensions-nullability
Jun 17, 2025
Merged

Fix nullable analysis involving extensions and collection expressions#78926
RikkiGibson merged 7 commits intodotnet:mainfrom
RikkiGibson:extensions-nullability

Conversation

@RikkiGibson
Copy link
Member

@RikkiGibson RikkiGibson commented Jun 11, 2025

Related to #78828 (fixes an assertion failure for a collection-expression involving extension Add)
Related to #68786.

I decided to go ahead and implement analysis of the mainline case of List<string> list = [null]; for example as there have been multiple bug reports about the diagnostic being missing. Analysis of extension Add methods is punted as it seems much less common.

@RikkiGibson RikkiGibson marked this pull request as ready for review June 16, 2025 05:05
@RikkiGibson RikkiGibson requested a review from a team as a code owner June 16, 2025 05:05
@jcouv jcouv self-assigned this Jun 16, 2025
@jcouv jcouv added the Feature - Extension Everything The extension everything feature label Jun 16, 2025
resultBuilder.Add(_visitResult);
}

void visitElement(BoundNode element)
Copy link
Member

@jcouv jcouv Jun 16, 2025

Choose a reason for hiding this comment

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

This local function captures, which will cause allocations
Also please avoid local function in the middle of the method logic (this could be done in a later commit to reduce diff for now)

comp.VerifyEmitDiagnostics(
// (7,19): warning CS8604: Possible null reference argument for parameter 'o' in 'void E.Add(MyCollection c, object o)'.
// MyCollection c = [oNull, oNotNull];
Diagnostic(ErrorCode.WRN_NullReferenceArgument, "oNull").WithArguments("o", "void E.Add(MyCollection c, object o)").WithLocation(7, 19));
Copy link
Member

@jcouv jcouv Jun 16, 2025

Choose a reason for hiding this comment

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

Analysis of extension Add methods is punted as it seems much less common.

nit: That seems fine. Consider adding tests to illustrate some of the known gaps (Add extension method on Collection<object> but our target collection type is Collection<object?>, for example)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (commit 6)

@jcouv jcouv added Feature - Collection Expressions and removed Feature - Extension Everything The extension everything feature labels Jun 16, 2025
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (commit 7)

@RikkiGibson RikkiGibson merged commit 69ec88d into dotnet:main Jun 17, 2025
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 17, 2025
CyrusNajmabadi added a commit to CyrusNajmabadi/roslyn that referenced this pull request Jun 18, 2025
Fix more

Update versions

Fix more

In progress

Flip

Fix

Fix

remove wrapper

Fix

Fix

in progress

Fix DeclarationKind layering

fix

One building

In progress

Breaking out refactoring helpers into core api vs service

VB side

In progress

Move type

workaround

Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CSharpCompilerExtensions.projitems

Fix SubText ctor parameter verification. (dotnet#78989)

* Fix SubText ctor parameter verification.

This ctor currently throws given a zero length span at the end (and only the end) of the subtext. This evidently became far more prevalent with this (fairly) recent change to optimize newline information in our sourcetext classes. (dotnet#74728)

It doesn't make to allow zero length spans at all locations but at the end of the subtext, so the fix is just to allow construction in that case too.

Big props to Manish Vasani for providing a very actionable repro for this.

Fixes dotnet#78985.

Note there is a potentially related issue outlined in dotnet#76225 that looks attributable to the PR above too. It possible that this addresses that issue too, but I'm not completely convinced.

Extensions: bind unconditionally of LangVer (dotnet#78947)

Extensions: use specific tracking issues for different areas (second pass) (dotnet#78971)

Fix nullable analysis involving extensions and collection expressions (dotnet#78926)

Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CSharpCompilerExtensions.projitems

in progrss

Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems

Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/VisualBasicCompilerExtensions.projitems

extensions

Fix

RootNamespace

Fixes

Fixes

IN progress

in progress
ToddGrun added a commit to ToddGrun/roslyn that referenced this pull request Jul 10, 2025
@RikkiGibson RikkiGibson removed this from the Next milestone Aug 19, 2025
@RikkiGibson RikkiGibson added this to the 18.0 P1 milestone Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants