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#: Ambiguous reference for names in automatic imports #332

Closed
mrmonday opened this issue Jul 18, 2019 · 2 comments · Fixed by #414
Closed

VB -> C#: Ambiguous reference for names in automatic imports #332

mrmonday opened this issue Jul 18, 2019 · 2 comments · Fixed by #414
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion

Comments

@mrmonday
Copy link
Contributor

Input code

File 1:

Namespace A
    Public Class Dictionary(Of V, K)
        Inherits System.Collections.Generic.Dictionary(Of K, V)
        Public Sub New()
        End Sub
    End Class
End Namespace

File 2:

Imports ConsoleApp4.A

Friend Class Program
    Public Shared Function Foo() As System.Collections.Generic.Dictionary(Of String, String)
        Return New Dictionary(Of String, String)()
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim x As List(Of String) = New List(Of String)()
    End Sub
End Class

Erroneous output

File 1:

namespace ConsoleApp4
{
    namespace A
    {
        public class Dictionary<V, K> : System.Collections.Generic.Dictionary<K, V>
        {
            public Dictionary()
            {
            }
        }
    }
}

File 2:

using System.Collections.Generic;
using ConsoleApp4.A;

namespace ConsoleApp4
{
    internal class Program
    {
        public static System.Collections.Generic.Dictionary<string, string> Foo()
        {
            return new Dictionary<string, string>();
        }

        public static void Main(string[] args)
        {
            List<string> x = new List<string>();
        }
    }
}

Error:

error CS0104: 'Dictionary<,>' is an ambiguous reference between 'ConsoleApp4.A.Dictionary<V, K>' and 'System.Collections.Generic.Dictionary<TKey, TValue>'

Expected output

File 1 - the same.

File 2:

using System.Collections.Generic;
using ConsoleApp4.A;

namespace ConsoleApp4
{
    internal class Program
    {
        public static System.Collections.Generic.Dictionary<string, string> Foo()
        {
            return new A.Dictionary<string, string>();
        }

        public static void Main(string[] args)
        {
            List<string> x = new List<string>();
        }
    }
}

The returned dictionary in Foo is explicitly qualified here. There are a few other ways to resolve this too.

Details

Product in use: VS extension

Version in use: 6.9.0.0

@GrahamTheCoder GrahamTheCoder added compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion labels Jul 20, 2019
@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Jul 20, 2019

I'm hoping that this can be tackled as part of the general Expand Reduce pattern we discussed previously. That's how the Roslyn diagnostics deal with such issues.

@GrahamTheCoder
Copy link
Member

I've now added the reduce pattern, so manually overqualifying everything is fine if it helps fix this.
I haven't added an expand step to try to automatically do this yet.

mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 12, 2019
mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 12, 2019
mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 13, 2019
mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 13, 2019
GrahamTheCoder added a commit that referenced this issue Nov 14, 2019
Correctly handle type promoted module symbols [#332, #375, #401]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion
Projects
None yet
2 participants