diff --git a/src/Features/CSharpTest/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs b/src/Features/CSharpTest/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs index 68460c3dc4d30..fa021ef3e571b 100644 --- a/src/Features/CSharpTest/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs +++ b/src/Features/CSharpTest/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.ReplaceMethodWithProperty; [Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)] -public class ReplaceMethodWithPropertyTests : AbstractCSharpCodeActionTest_NoEditor +public sealed class ReplaceMethodWithPropertyTests : AbstractCSharpCodeActionTest_NoEditor { protected override CodeRefactoringProvider CreateCodeRefactoringProvider(TestWorkspace workspace, TestParameters parameters) => new ReplaceMethodWithPropertyCodeRefactoringProvider(); diff --git a/src/Features/CSharpTest/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs b/src/Features/CSharpTest/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs index fb9bdd58cfd6c..efeb6a9e832d6 100644 --- a/src/Features/CSharpTest/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs +++ b/src/Features/CSharpTest/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.ReplacePropertyWithMethods; [Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)] -public class ReplacePropertyWithMethodsTests : AbstractCSharpCodeActionTest_NoEditor +public sealed class ReplacePropertyWithMethodsTests : AbstractCSharpCodeActionTest_NoEditor { private OptionsCollection PreferExpressionBodiedMethods => new(GetLanguage()) { { CSharpCodeStyleOptions.PreferExpressionBodiedMethods, CSharpCodeStyleOptions.WhenPossibleWithSuggestionEnforcement } }; @@ -2490,4 +2490,29 @@ private static void SetSomeValue(int value) } """); } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75135")] + public async Task TestMatchInPropertyPattern() + { + await TestInRegularAndScriptAsync(""" + class C + { + public int [||]Property { get { return 0; } } + public bool M() + { + return this is { Property: 1 }; + } + } + """, """ + class C + { + public int GetProperty() + { return 0; } + public bool M() + { + return this is { {|Conflict:Property|}: 1 }; + } + } + """); + } } diff --git a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs index 4ee3036711cf9..f91a90d242522 100644 --- a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs @@ -275,6 +275,11 @@ private async Task ReplaceReferencesAsync( editor.ReplaceNode(parent, parent.WithAdditionalAnnotations( ConflictAnnotation.Create(FeaturesResources.Property_reference_cannot_be_updated))); } + else if (syntaxFacts.IsNameOfSubpattern(parent)) + { + editor.ReplaceNode(parent, parent.WithAdditionalAnnotations( + ConflictAnnotation.Create(FeaturesResources.Property_reference_cannot_be_updated))); + } else { var fieldSymbol = propertyToBackingField.GetValueOrDefault(property);