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

Open
mrmonday opened this issue Jul 18, 2019 · 2 comments

Comments

@mrmonday
Copy link
Contributor

commented Jul 18, 2019

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Aug 16, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.