Skip to content

Commit f29af8b

Browse files
committed
Add regression test for #827 in correct location, fix comment indentation
- Add TestOverridableAutoPropertyBackingFieldAccessAsync to Tests/CSharp/MemberTests/PropertyMemberTests.cs (VB->CS tests) covering the exact issue #827 scenario: _Prop = 10 converts to MyClassProp = 10 - Remove duplicate test from Tests/VB/MemberTests.cs where VB->CS tests do not belong - Fix indentation of comment in CommonConversions.cs https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent 9ed5ef6 commit f29af8b

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

CodeConverter/CSharp/CommonConversions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Immutable;
1+
using System.Collections.Immutable;
22
using System.Linq.Expressions;
33
using System.Runtime.CompilerServices;
44
using ICSharpCode.CodeConverter.Util.FromRoslyn;
@@ -293,7 +293,7 @@ public SyntaxToken ConvertIdentifier(SyntaxToken id, bool isAttribute = false, S
293293
// AND the first explicitly declared parameter is this symbol, we need to replace it with value.
294294
text = "value";
295295
} else if (normalizedText.StartsWith("_", StringComparison.OrdinalIgnoreCase) && idSymbol is IFieldSymbol propertyFieldSymbol && propertyFieldSymbol.AssociatedSymbol?.IsKind(SymbolKind.Property) == true) {
296-
// For virtual auto-properties, VB backing field _Prop maps to the C# MyClassProp backing property
296+
// For virtual auto-properties, VB backing field _Prop maps to the C# MyClassProp backing property (bypasses virtual dispatch)
297297
text = propertyFieldSymbol.IsImplicitlyDeclared && propertyFieldSymbol.AssociatedSymbol is IPropertySymbol { IsVirtual: true, IsAbstract: false } vProp
298298
? "MyClass" + vProp.Name
299299
: propertyFieldSymbol.AssociatedSymbol.Name;

Tests/CSharp/MemberTests/PropertyMemberTests.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using ICSharpCode.CodeConverter.Tests.TestRunners;
33
using Xunit;
44

@@ -874,4 +874,49 @@ public static IEnumerable<object[]> SomeObjects
874874
}
875875
}");
876876
}
877-
}
877+
/// <summary>Issue #827: VB auto-property backing field access (_Prop) should map to MyClassProp for overridable properties</summary>
878+
[Fact]
879+
public async Task TestOverridableAutoPropertyBackingFieldAccessAsync()
880+
{
881+
await TestConversionVisualBasicToCSharpAsync(@"Class Foo
882+
Overridable Property Prop As Integer = 5
883+
884+
Sub Test()
885+
_Prop = 10
886+
Dim isCorrect = MyClass.Prop = 10
887+
End Sub
888+
End Class
889+
Class Child
890+
Inherits Foo
891+
Overrides Property Prop As Integer = 20
892+
End Class", @"
893+
internal partial class Foo
894+
{
895+
public int MyClassProp { get; set; } = 5;
896+
897+
public virtual int Prop
898+
{
899+
get
900+
{
901+
return MyClassProp;
902+
}
903+
904+
set
905+
{
906+
MyClassProp = value;
907+
}
908+
}
909+
910+
public void Test()
911+
{
912+
MyClassProp = 10;
913+
bool isCorrect = MyClassProp == 10;
914+
}
915+
}
916+
917+
internal partial class Child : Foo
918+
{
919+
public override int Prop { get; set; } = 20;
920+
}");
921+
}
922+
}

Tests/VB/MemberTests.cs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using ICSharpCode.CodeConverter.Tests.TestRunners;
33
using ICSharpCode.CodeConverter.VB;
44
using Xunit;
@@ -1495,49 +1495,4 @@ End Sub
14951495
End Class");
14961496
}
14971497

1498-
1499-
[Fact]
1500-
public async Task TestMyClassPropertyAccess()
1501-
{
1502-
await TestConversionVisualBasicToCSharpAsync(@"
1503-
Class Foo
1504-
Overridable Property Prop As Integer = 5
1505-
1506-
Sub Test()
1507-
_Prop = 10 ' This should convert to MyClassProp = 10 not to Prop = 10
1508-
Dim isCorrect = MyClass.Prop = 10 ' After conversion this will return 5instead of 10 because we wrote to Child.Prop
1509-
End Sub
1510-
End Class
1511-
Class Child
1512-
Inherits Foo
1513-
Overrides Property Prop As Integer = 20
1514-
End Class", @"
1515-
internal partial class Foo
1516-
{
1517-
public int MyClassProp { get; set; } = 5;
1518-
1519-
public virtual int Prop
1520-
{
1521-
get
1522-
{
1523-
return MyClassProp;
1524-
}
1525-
1526-
set
1527-
{
1528-
MyClassProp = value;
1529-
}
1530-
}
1531-
1532-
public void Test()
1533-
{
1534-
MyClassProp = 10; // This should convert to MyClassProp = 10 not to Prop = 10
1535-
bool isCorrect = MyClassProp == 10; // After conversion this will return 5instead of 10 because we wrote to Child.Prop
1536-
}
1537-
}
1538-
internal partial class Child : Foo
1539-
{
1540-
public override int Prop { get; set; } = 20;
1541-
}");
1542-
}
15431498
}

0 commit comments

Comments
 (0)