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

VB -> C#: Missing index for dictionary access #362

Closed
mrmonday opened this issue Aug 21, 2019 · 0 comments · Fixed by #407
Closed

VB -> C#: Missing index for dictionary access #362

mrmonday opened this issue Aug 21, 2019 · 0 comments · Fixed by #407
Labels
output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion

Comments

@mrmonday
Copy link
Contributor

Input code

Imports System
Imports System.Collections.Generic

Module Module1
    Dim Dict As New Dictionary(Of Integer, String)

    Sub Main()
        Dim x = Dict.Values(0).Length
    End Sub
End Module

Erroneous output

using System.Collections.Generic;

namespace ConsoleApp10
{
    static class Module1
    {
        private static Dictionary<int, string> Dict = new Dictionary<int, string>();

        public static void Main()
        {
            var x = Dict.Values.Length;
        }
    }
}

Expected output

using System.Collections.Generic;

namespace ConsoleApp10
{
    static class Module1
    {
        private static Dictionary<int, string> Dict = new Dictionary<int, string>();

        public static void Main()
        {
            var x = Dict.Values[0].Length;
        }
    }
}

Details

Version in use: master @ 2483369

This case is quite interesting, since it's still valid code - it just does the wrong thing. My original case was with a dictionary of some other class, with some other property, so the code did not compile.

@GrahamTheCoder GrahamTheCoder added output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion labels Aug 21, 2019
mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 11, 2019
Ensure parameterless property access short-circuit only happens when
there are no parameters. This allows the existing code for
`ElementAtOrDefault` to be triggered correctly.

Closes icsharpcode#362
mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 11, 2019
Ensure parameterless property access short-circuit only happens when
there are no parameters. This allows the existing code for
`ElementAtOrDefault` to be triggered correctly.

Fixes icsharpcode#362
GrahamTheCoder added a commit that referenced this issue Nov 11, 2019
VB -> C#: Fix implicit `ElementAtOrDefault` usage [#362]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants