icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
826 stars 216 forks source link

VB -> C#: Exit Property is resolved incorrectly #1051

Closed TymurGubayev closed 9 months ago

TymurGubayev commented 10 months ago

(the Function code below is for comparison)

VB.Net input code

    Public ReadOnly Property Prop() As Object
        Get
            Try
                Prop = New Object
                Exit Property
            Catch ex As Exception
            End Try
        End Get
    End Property

    Public Function Func() As Object
        Try
            Func = New Object
            Exit Function
        Catch ex As Exception
        End Try
    End Function

Erroneous output

        public object Prop
        {
            get
            {
                object PropRet = default;
                try
                {
                    PropRet = new object();
                    return default; //this should've been `PropRet`
                }
                catch (Exception ex)
                {
                }

                return PropRet;
            }
        }

        public object Func()
        {
            object FuncRet = default;
            try
            {
                FuncRet = new object();
                return FuncRet;
            }
            catch (Exception ex)
            {
            }

            return FuncRet;
        }

Expected output

        public object Prop
        {
            get
            {
                object PropRet = default;
                try
                {
                    PropRet = new object();
                    return PropRet;
                }
                catch (Exception ex)
                {
                }

                return PropRet;
            }
        }

        public object Func()
        {
            object FuncRet = default;
            try
            {
                FuncRet = new object();
                return FuncRet;
            }
            catch (Exception ex)
            {
            }

            return FuncRet;
        }

Details