diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateDeconstructMethodTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateDeconstructMethodTests.cs index 1c38de1abb4d5ada918a9e5d8895507d9a88e407..4ff7e2a6bd5b5eb7a45e8c54d0ef54bd05df2aae 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateDeconstructMethodTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateDeconstructMethodTests.cs @@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateDeconstructMethod; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; +using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.GenerateDeconstructMethod @@ -294,6 +295,26 @@ internal void Deconstruct(out int x, out int y) { throw new NotImplementedException(); } +}"); + } + + [WorkItem(32510, "https://github.com/dotnet/roslyn/issues/32510")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)] + public async Task TestDeconstructionAssignment_InvalidDeclaration() + { + await TestMissingInRegularAndScriptAsync( +@" +using System.Collections.Generic; + +class C +{ + void Method() + { + var stuff = new Dictionary(); + foreach ((key, value) in [|stuff|]) // Invalid variable declarator syntax + { + } + } }"); } } diff --git a/src/Features/CSharp/Portable/CodeFixes/GenerateMethod/GenerateDeconstructMethodCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/GenerateMethod/GenerateDeconstructMethodCodeFixProvider.cs index e1900da63d2812e4b39feb462b8d1ff6eb0cf7a6..04e7d0cf47c79a3e5da99c650d015c3de5a4d1fb 100644 --- a/src/Features/CSharp/Portable/CodeFixes/GenerateMethod/GenerateDeconstructMethodCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/GenerateMethod/GenerateDeconstructMethodCodeFixProvider.cs @@ -68,7 +68,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) throw ExceptionUtilities.Unreachable; } - if (type.Kind != SymbolKind.NamedType) + if (type?.Kind != SymbolKind.NamedType) { return; }