@@ -17719,6 +17719,27 @@ public void Property_ExpressionBody_Update()
1771917719 ]);
1772017720 }
1772117721
17722+ [Fact]
17723+ public void Property_ExpressionBody_Update_Auto_FieldAccess()
17724+ {
17725+ var src1 = "class C { int P => 1; }";
17726+ var src2 = "class C { int P => field; }";
17727+
17728+ var edits = GetTopEdits(src1, src2);
17729+
17730+ edits.VerifyEdits(
17731+ "Update [int P => 1;]@10 -> [int P => field;]@10",
17732+ "Update [=> 1]@16 -> [=> field]@16");
17733+
17734+ edits.VerifySemantics(
17735+ [SemanticEdit(SemanticEditKind.Update, c => c.GetMember<IPropertySymbol>("C.P").GetMethod)],
17736+ capabilities: EditAndContinueCapabilities.AddInstanceFieldToExistingType);
17737+
17738+ edits.VerifySemanticDiagnostics(
17739+ [Diagnostic(RudeEditKind.InsertNotSupportedByRuntime, "int P", GetResource("property getter"))],
17740+ capabilities: EditAndContinueCapabilities.Baseline);
17741+ }
17742+
1772217743 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48628")]
1772317744 public void Property_ExpressionBody_ModifierUpdate()
1772417745 {
@@ -17818,6 +17839,124 @@ public void Property_BlockBodyToExpressionBody2()
1781817839 capabilities: EditAndContinueCapabilities.Baseline);
1781917840 }
1782017841
17842+ [Fact]
17843+ public void Property_BlockBodyToExpressionBody_Auto_FieldAccess()
17844+ {
17845+ var src1 = "class C { int P { get { return field; } set; } }";
17846+ var src2 = "class C { int P => field; }";
17847+
17848+ var edits = GetTopEdits(src1, src2);
17849+
17850+ edits.VerifyEdits(
17851+ "Update [int P { get { return field; } set; }]@10 -> [int P => field;]@10",
17852+ "Insert [=> field]@16",
17853+ "Delete [{ get { return field; } set; }]@16",
17854+ "Delete [get { return field; }]@18",
17855+ "Delete [set;]@40");
17856+
17857+ edits.VerifySemantics(
17858+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P")),
17859+ SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")));
17860+ }
17861+
17862+ [Fact]
17863+ public void Property_BlockBodyToGetterExpressionBody_Auto_FieldAccess()
17864+ {
17865+ var src1 = "class C { int P { get { return field; } set; } }";
17866+ var src2 = "class C { int P { get => field; } }";
17867+
17868+ var edits = GetTopEdits(src1, src2);
17869+
17870+ edits.VerifyEdits(
17871+ "Update [get { return field; }]@18 -> [get => field;]@18",
17872+ "Delete [set;]@40");
17873+
17874+ edits.VerifySemantics(
17875+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P")),
17876+ SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")));
17877+ }
17878+
17879+ [Fact]
17880+ public void Property_BlockBody_Update_SetAccessor_Auto_FieldAccess()
17881+ {
17882+ var src1 = "class C { int P { get { return field; } set; } }";
17883+ var src2 = "class C { int P { get { return field; } set { field = value; } } }";
17884+
17885+ var edits = GetTopEdits(src1, src2);
17886+
17887+ edits.VerifyEdits(
17888+ "Update [set;]@40 -> [set { field = value; }]@40");
17889+
17890+ edits.VerifySemantics(
17891+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.set_P")));
17892+ }
17893+
17894+ [Fact]
17895+ public void Property_Auto_GetterBlockBodyToGetterExpressionBody_FieldAccess()
17896+ {
17897+ var src1 = "class C { int P { get { return field; } } }";
17898+ var src2 = "class C { int P { get => field; } }";
17899+
17900+ var edits = GetTopEdits(src1, src2);
17901+
17902+ edits.VerifyEdits(
17903+ "Update [get { return field; }]@18 -> [get => field;]@18");
17904+
17905+ edits.VerifySemantics(
17906+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P")));
17907+ }
17908+
17909+ [Fact]
17910+ public void Property_Auto_SetterBlockBodyToSetterExpressionBody_FieldAccess()
17911+ {
17912+ var src1 = "class C { int P { set { field = value; } } }";
17913+ var src2 = "class C { int P { set => field = value; } }";
17914+
17915+ var edits = GetTopEdits(src1, src2);
17916+
17917+ edits.VerifyEdits(
17918+ "Update [set { field = value; }]@18 -> [set => field = value;]@18");
17919+
17920+ edits.VerifySemantics(
17921+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember<INamedTypeSymbol>("C").GetMember<IPropertySymbol>("P").SetMethod));
17922+ }
17923+
17924+ [Fact]
17925+ public void Property_Auto_ExpressionBodyToGetterExpressionBody_FieldAccess()
17926+ {
17927+ var src1 = "class C { int P => field; }";
17928+ var src2 = "class C { int P { get => field; } }";
17929+
17930+ var edits = GetTopEdits(src1, src2);
17931+
17932+ edits.VerifyEdits(
17933+ "Update [int P => field;]@10 -> [int P { get => field; }]@10",
17934+ "Insert [{ get => field; }]@16",
17935+ "Insert [get => field;]@18",
17936+ "Delete [=> field]@16");
17937+
17938+ edits.VerifySemantics(
17939+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P")));
17940+ }
17941+
17942+ [Fact]
17943+ public void Property_Auto_GetterExpressionBodyToExpressionBody_FieldAccess()
17944+ {
17945+ var src1 = "class C { int P { get => field; } }";
17946+ var src2 = "class C { int P => field; }";
17947+
17948+ var edits = GetTopEdits(src1, src2);
17949+
17950+ edits.VerifyEdits(
17951+ "Update [int P { get => field; }]@10 -> [int P => field;]@10",
17952+ "Insert [=> field]@16",
17953+ "Delete [{ get => field; }]@16",
17954+ "Delete [get => field;]@18");
17955+
17956+ edits.VerifySemantics(
17957+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P")));
17958+ }
17959+
1782117960 [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17681")]
1782217961 public void Property_ExpressionBodyToGetterExpressionBody()
1782317962 {
@@ -18655,6 +18794,7 @@ struct S
1865518794{
1865618795 public int a;
1865718796 static int c { get; set; }
18797+ static int d { get => field; set; }
1865818798 static int e { get { return 0; } set { } }
1865918799 static int g { get; } = 1;
1866018800 static int i { get; set; } = 1;
@@ -18669,6 +18809,7 @@ struct S
1866918809
1867018810 edits.VerifySemanticDiagnostics(
1867118811 Diagnostic(RudeEditKind.InsertOrMoveStructMember, "static int c", GetResource("auto-property"), GetResource("struct")),
18812+ Diagnostic(RudeEditKind.InsertOrMoveStructMember, "static int d", GetResource("auto-property"), GetResource("struct")),
1867218813 Diagnostic(RudeEditKind.InsertOrMoveStructMember, "static int g", GetResource("auto-property"), GetResource("struct")),
1867318814 Diagnostic(RudeEditKind.InsertOrMoveStructMember, "static int i", GetResource("auto-property"), GetResource("struct")));
1867418815 }
@@ -18686,6 +18827,31 @@ public void Property_Insert_Auto()
1868618827 capabilities: EditAndContinueCapabilities.AddMethodToExistingType | EditAndContinueCapabilities.AddInstanceFieldToExistingType);
1868718828 }
1868818829
18830+ [Fact]
18831+ public void Property_Insert_Auto_FieldAccess()
18832+ {
18833+ var src1 = "class C { }";
18834+ var src2 = "class C { int P { get; set => field = value; } }";
18835+
18836+ var edits = GetTopEdits(src1, src2);
18837+
18838+ edits.VerifyEdits(
18839+ "Insert [int P { get; set => field = value; }]@10",
18840+ "Insert [{ get; set => field = value; }]@16",
18841+ "Insert [get;]@18",
18842+ "Insert [set => field = value;]@23");
18843+
18844+ edits.VerifySemantics(
18845+ [SemanticEdit(SemanticEditKind.Insert, c => c.GetMember<INamedTypeSymbol>("C").GetMember("P"))],
18846+ capabilities:
18847+ EditAndContinueCapabilities.AddMethodToExistingType |
18848+ EditAndContinueCapabilities.AddInstanceFieldToExistingType);
18849+
18850+ edits.VerifySemanticDiagnostics(
18851+ [Diagnostic(RudeEditKind.InsertNotSupportedByRuntime, "int P", GetResource("auto-property"))],
18852+ capabilities: EditAndContinueCapabilities.Baseline);
18853+ }
18854+
1868918855 [Fact]
1869018856 public void Property_Insert_Auto_Static()
1869118857 {
@@ -18699,6 +18865,31 @@ public void Property_Insert_Auto_Static()
1869918865 capabilities: EditAndContinueCapabilities.AddMethodToExistingType | EditAndContinueCapabilities.AddStaticFieldToExistingType);
1870018866 }
1870118867
18868+ [Fact]
18869+ public void Property_Insert_Auto_Static_FieldAccess()
18870+ {
18871+ var src1 = "class C { }";
18872+ var src2 = "class C { static int P { get; set => field = value; } }";
18873+
18874+ var edits = GetTopEdits(src1, src2);
18875+
18876+ edits.VerifyEdits(
18877+ "Insert [static int P { get; set => field = value; }]@10",
18878+ "Insert [{ get; set => field = value; }]@23",
18879+ "Insert [get;]@25",
18880+ "Insert [set => field = value;]@30");
18881+
18882+ edits.VerifySemantics(
18883+ [SemanticEdit(SemanticEditKind.Insert, c => c.GetMember<INamedTypeSymbol>("C").GetMember("P"))],
18884+ capabilities:
18885+ EditAndContinueCapabilities.AddMethodToExistingType |
18886+ EditAndContinueCapabilities.AddStaticFieldToExistingType);
18887+
18888+ edits.VerifySemanticDiagnostics(
18889+ [Diagnostic(RudeEditKind.InsertNotSupportedByRuntime, "static int P", GetResource("auto-property"))],
18890+ capabilities: EditAndContinueCapabilities.Baseline);
18891+ }
18892+
1870218893 [Fact]
1870318894 public void Property_Insert_Auto_GenericType()
1870418895 {
@@ -18720,6 +18911,35 @@ public void Property_Insert_Auto_GenericType()
1872018911 capabilities: EditAndContinueCapabilities.AddMethodToExistingType | EditAndContinueCapabilities.AddInstanceFieldToExistingType);
1872118912 }
1872218913
18914+ [Fact]
18915+ public void Property_Insert_Auto_GenericType_FieldAccess()
18916+ {
18917+ var src1 = "class C<T> { }";
18918+ var src2 = "class C<T> { int P { get; set => field = value; } }";
18919+
18920+ var edits = GetTopEdits(src1, src2);
18921+
18922+ edits.VerifyEdits(
18923+ "Insert [int P { get; set => field = value; }]@13",
18924+ "Insert [{ get; set => field = value; }]@19",
18925+ "Insert [get;]@21",
18926+ "Insert [set => field = value;]@26");
18927+
18928+ edits.VerifySemantics(
18929+ [SemanticEdit(SemanticEditKind.Insert, c => c.GetMember<INamedTypeSymbol>("C").GetMember("P"))],
18930+ capabilities:
18931+ EditAndContinueCapabilities.AddMethodToExistingType |
18932+ EditAndContinueCapabilities.AddInstanceFieldToExistingType |
18933+ EditAndContinueCapabilities.GenericAddMethodToExistingType |
18934+ EditAndContinueCapabilities.GenericAddFieldToExistingType);
18935+
18936+ edits.VerifySemanticDiagnostics(
18937+ [Diagnostic(RudeEditKind.InsertNotSupportedByRuntime, "int P", GetResource("auto-property"))],
18938+ capabilities:
18939+ EditAndContinueCapabilities.AddMethodToExistingType |
18940+ EditAndContinueCapabilities.AddInstanceFieldToExistingType);
18941+ }
18942+
1872318943 [Fact]
1872418944 public void Property_Insert_Auto_GenericType_Static()
1872518945 {
@@ -18741,6 +18961,35 @@ public void Property_Insert_Auto_GenericType_Static()
1874118961 capabilities: EditAndContinueCapabilities.AddMethodToExistingType | EditAndContinueCapabilities.AddStaticFieldToExistingType);
1874218962 }
1874318963
18964+ [Fact]
18965+ public void Property_Insert_Auto_GenericType_Static_FieldAccess()
18966+ {
18967+ var src1 = "class C<T> { }";
18968+ var src2 = "class C<T> { static int P { get; set => field = value; } }";
18969+
18970+ var edits = GetTopEdits(src1, src2);
18971+
18972+ edits.VerifyEdits(
18973+ "Insert [static int P { get; set => field = value; }]@13",
18974+ "Insert [{ get; set => field = value; }]@26",
18975+ "Insert [get;]@28",
18976+ "Insert [set => field = value;]@33");
18977+
18978+ edits.VerifySemantics(
18979+ [SemanticEdit(SemanticEditKind.Insert, c => c.GetMember<INamedTypeSymbol>("C").GetMember("P"))],
18980+ capabilities:
18981+ EditAndContinueCapabilities.AddMethodToExistingType |
18982+ EditAndContinueCapabilities.AddStaticFieldToExistingType |
18983+ EditAndContinueCapabilities.GenericAddMethodToExistingType |
18984+ EditAndContinueCapabilities.GenericAddFieldToExistingType);
18985+
18986+ edits.VerifySemanticDiagnostics(
18987+ [Diagnostic(RudeEditKind.InsertNotSupportedByRuntime, "static int P", GetResource("auto-property"))],
18988+ capabilities:
18989+ EditAndContinueCapabilities.AddMethodToExistingType |
18990+ EditAndContinueCapabilities.AddStaticFieldToExistingType);
18991+ }
18992+
1874418993 // Design: Adding private accessors should also be allowed since we now allow adding private methods
1874518994 // and adding public properties and/or public accessors are not allowed.
1874618995 [Fact]
@@ -19076,6 +19325,36 @@ public void Property_Auto_Accessor_Update_ReplacingImplicitWithExpressionBodiedP
1907619325 capabilities: EditAndContinueCapabilities.Baseline);
1907719326 }
1907819327
19328+ [Fact]
19329+ public void Property_Auto_Accessor_Update_ReplaceImplicitGetWithExpressionBody_FieldAccess()
19330+ {
19331+ var src1 = "class C { int P { get; } }";
19332+ var src2 = "class C { int P { get => field; } }";
19333+
19334+ var edits = GetTopEdits(src1, src2);
19335+
19336+ edits.VerifyEdits(
19337+ "Update [get;]@18 -> [get => field;]@18");
19338+
19339+ edits.VerifySemantics(
19340+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember<IPropertySymbol>("C.P").GetMethod));
19341+ }
19342+
19343+ [Fact]
19344+ public void Property_Auto_Accessor_Update_ReplaceImplicitSetWithExpressionBody_FieldAccess()
19345+ {
19346+ var src1 = "class C { int P { get; set; } }";
19347+ var src2 = "class C { int P { get; set => field = value; } }";
19348+
19349+ var edits = GetTopEdits(src1, src2);
19350+
19351+ edits.VerifyEdits(
19352+ "Update [set;]@23 -> [set => field = value;]@23");
19353+
19354+ edits.VerifySemantics(
19355+ SemanticEdit(SemanticEditKind.Update, c => c.GetMember<IPropertySymbol>("C.P").SetMethod));
19356+ }
19357+
1907919358 [Fact]
1908019359 public void Property_ReadOnlyRef_Insert()
1908119360 {
0 commit comments