Skip to content

Rare MyClass case converts incorrectly #827

@GrahamTheCoder

Description

@GrahamTheCoder

Accessing backing field of the autogenerated property where MyClass is involved:

Class Foo 
    Overridable Property Prop As Integer = 5

    Sub Test()
        _Prop = 10 ' This should convert to MyClassProp = 10 not to Prop = 10
        Dim isCorrect = MyClass.Prop = 10 ' After conversion this will return 5instead of 10 because we wrote to Child.Prop
    End Sub
End Class
Class Child
    Inherits Foo
    Overrides Property Prop As Integer = 20
End Class
    public class Foo
    {
        public int MyClassProp { get; set; } = 5;

        public virtual int Prop
        {
            get => MyClassProp;

            set => MyClassProp = value;
        }

        public void Test()
        {
            Prop = 10; // This should convert to MyClassProp = 10 not to Prop = 10
            bool isCorrect = MyClassProp == 10; // After conversion this will return 5 instead of 10 because we wrote to Child.Prop
        }
    }

    public class Child : Foo
    {
        public override int Prop { get; set; } = 20;
    }

Originally posted by @Yozer in #822 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good for coding agentCoding agent might get it in one - small change with reproVB -> C#Specific to VB -> C# conversionoutput logic errorA bug where the converted output behaves differently to the input code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions