Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when converting properties to methods #75256

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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 @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
Expand Down Expand Up @@ -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 };
}
}
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading