diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Nullable/CSharpDeclareAsNullableCodeFixTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Nullable/CSharpDeclareAsNullableCodeFixTests.cs index 9a49294320dd5..66b792e6f20f3 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Nullable/CSharpDeclareAsNullableCodeFixTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Nullable/CSharpDeclareAsNullableCodeFixTests.cs @@ -832,6 +832,22 @@ void M2(string? x) { } }", parameters: s_nullableFeature); } + [Fact] + [WorkItem(44338, "https://github.com/dotnet/roslyn/issues/44338")] + public async Task NoFixInvocationOfExternalMethod_NamedArgument() + { + await TestMissingInRegularAndScriptAsync( +@"#nullable enable +class Program +{ + void M() + { + var list = new System.Collections.Generic.List(); + list.Add(item: [|null|]); + } +}", parameters: s_nullableFeature); + } + [Fact] public async Task FixInvocation_NamedArgument_OutOfOrder() { @@ -856,6 +872,22 @@ void M2(int i, string? x) { } }", parameters: s_nullableFeature); } + [Fact] + [WorkItem(44338, "https://github.com/dotnet/roslyn/issues/44338")] + public async Task NoFixInvocationOfExternalMethod_NamedArgument_OutOfOrder() + { + await TestMissingInRegularAndScriptAsync( +@"#nullable enable +class Program +{ + void M() + { + var dict = new System.Collections.Generic.Dictionary(); + dict.Add(value: 0, key: [|null|]); + } +}", parameters: s_nullableFeature); + } + [Fact] public async Task FixInvocation_NamedArgument_Partial() { @@ -896,6 +928,22 @@ void M2(string? x) { } }", parameters: s_nullableFeature); } + [Fact] + [WorkItem(44338, "https://github.com/dotnet/roslyn/issues/44338")] + public async Task NoFixInvocationOfExternalMethod_PositionArgument() + { + await TestMissingInRegularAndScriptAsync( +@"#nullable enable +class Program +{ + void M() + { + var list = new System.Collections.Generic.List(); + list.Add([|null|]); + } +}", parameters: s_nullableFeature); + } + [Fact] public async Task FixInvocation_PositionArgument_SecondPosition() { diff --git a/src/Features/CSharp/Portable/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs index 9bde063178b72..5272750ef3986 100644 --- a/src/Features/CSharp/Portable/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs @@ -340,7 +340,7 @@ declarator.Parent is VariableDeclarationSyntax declaration && static TypeSyntax? TryGetParameterTypeSyntax(IParameterSymbol? parameterSymbol) { if (parameterSymbol is object && - parameterSymbol.DeclaringSyntaxReferences[0].GetSyntax() is ParameterSyntax parameterSyntax && + parameterSymbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is ParameterSyntax parameterSyntax && parameterSymbol.ContainingSymbol is IMethodSymbol method && method.GetAllMethodSymbolsOfPartialParts().Length == 1) {