Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3913,6 +3913,14 @@

var argIndex = initializer.AddMethod.IsExtensionMethod ? 1 : 0;
Debug.Assert(initializer.ArgsToParamsOpt.IsDefault);

Check failure on line 3916 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3916

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3916,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 3916 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3916

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3916,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 3916 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3916

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3916,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 3916 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3916

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3916,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
// For extension methods, mark the receiver argument with unknown nullability
// since we don't analyze it (we only analyze the element argument).
if (initializer.AddMethod.IsExtensionMethod)
{
SetUnknownResultNullability(initializer.Arguments[0]);
}

Check failure on line 3923 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3923

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3923,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 3923 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3923

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3923,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 3923 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3923

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3923,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 3923 in src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs#L3923

src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs(3923,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
var addArgument = initializer.Arguments[argIndex];
VisitRvalue(addArgument);
var addArgumentResult = _visitResult;
Expand Down
30 changes: 30 additions & 0 deletions src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49191,6 +49191,36 @@ public class MyCollection<T> : IEnumerable<T>
comp.VerifyEmitDiagnostics();
}

[Fact]
public void Nullability_CollectionExpression_ExtensionAdd()
{
var src = """
#nullable enable
using System.Collections;
using System.Collections.Generic;

object? oNull = null;
object oNotNull = new object();
MyCollection c = [oNull, oNotNull];

static class E
{
public static void Add(this MyCollection c, object o) { }
}

public class MyCollection : IEnumerable<object>
{
IEnumerator<object> IEnumerable<object>.GetEnumerator() => throw null!;
IEnumerator IEnumerable.GetEnumerator() => throw null!;
}
""";
var comp = CreateCompilation(src);
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));
}

[Fact]
public void Nullability_ObjectInitializer_01()
{
Expand Down
Loading