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#: Type conversions of integer values vanish in inferred generic types #1159

Open
gaschd opened this issue Nov 11, 2024 · 0 comments
Open
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@gaschd
Copy link
Contributor

gaschd commented Nov 11, 2024

The array types are correct, but the necessary type casts are missing.
This issue seems to only affect integer values, which need to be explicitly cast to the appropriate types.

VB.Net input code

Imports System
Imports System.Linq

Public Class TestClass
    Public Sub GenerateFromConstants
        Dim floatArr = Enumerable.Repeat(1.0F, 5).ToArray()        
        Dim doubleArr = Enumerable.Repeat(2.0, 5).ToArray()        
        Dim decimalArr = Enumerable.Repeat(3.0D, 5).ToArray()    
    End Sub

    Public Sub GenerateFromCasts
        Dim floatArr = Enumerable.Repeat(CSng(1), 5).ToArray()        
        Dim doubleArr = Enumerable.Repeat(CDbl(2), 5).ToArray()        
        Dim decimalArr = Enumerable.Repeat(CDec(3), 5).ToArray()  
    End Sub
End Class

Erroneous output

using System;
using System.Linq;
using Microsoft.VisualBasic.CompilerServices; // Install-Package Microsoft.VisualBasic

public partial class TestClass
{
    public void GenerateFromConstants()
    {
        float[] floatArr = Enumerable.Repeat(1.0f, 5).ToArray();
        double[] doubleArr = Enumerable.Repeat(2.0d, 5).ToArray();
        decimal[] decimalArr = Enumerable.Repeat(3.0m, 5).ToArray();
    }

    public void GenerateFromCasts()
    {
        float[] floatArr = Enumerable.Repeat(1, 5).ToArray();
        double[] doubleArr = Enumerable.Repeat(2, 5).ToArray();
        decimal[] decimalArr = Enumerable.Repeat(3, 5).ToArray();          
    }
}
3 target compilation errors:
CS0029: Cannot implicitly convert type 'int[]' to 'float[]'
CS0029: Cannot implicitly convert type 'int[]' to 'double[]'
CS0029: Cannot implicitly convert type 'int[]' to 'decimal[]'

Expected output

using System;
using System.Linq;
using Microsoft.VisualBasic.CompilerServices; // Install-Package Microsoft.VisualBasic

public partial class TestClass
{
    public void GenerateFromConstants()
    {
        float[] floatArr = Enumerable.Repeat(1.0f, 5).ToArray();
        double[] doubleArr = Enumerable.Repeat(2.0d, 5).ToArray();
        decimal[] decimalArr = Enumerable.Repeat(3.0m, 5).ToArray();
    }

    public void GenerateFromCasts()
    {
        float[] floatArr = Enumerable.Repeat((float)1, 5).ToArray();
        double[] doubleArr = Enumerable.Repeat((double)2, 5).ToArray();
        decimal[] decimalArr = Enumerable.Repeat((decimal)3, 5).ToArray();          
    }
}

Details

  • Product in use: Test
  • Version in use: master abea701
@gaschd gaschd added the VB -> C# Specific to VB -> C# conversion label Nov 11, 2024
gaschd added a commit to gaschd/CodeConverter that referenced this issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant