提交 cf911f2f 编写于 作者: G Gen Lu

Support having multiple identical aliases as ext methods' target type

上级 7a5229f1
......@@ -1096,9 +1096,9 @@ public void M(int x)
}
[InlineData("int", "Int32Method", "Foo")]
[InlineData("string", "StringMethod", "Bar", Skip = "Currently can't handle aliases with idencical name")]
[InlineData("string", "StringMethod", "Bar")]
[Theory, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task TestIdenticalAlias_UseOuterOne(string type, string expectedMethodname, string expectedNamespace)
public async Task TestIdenticalAliases(string type, string expectedMethodname, string expectedNamespace)
{
var file1 = @"
using X = System.String;
......
......@@ -120,12 +120,26 @@ internal sealed partial class SyntaxTreeIndex
{
foreach (var (aliasName, name) in aliases)
{
// TODO:
// we currently don't handle using aliases with same name declared
// in different containers in the document (only allowed in C#)
// e.g. see test CSharpReferenceHighlightingTests.TestAlias4
// Debug.Assert(!usingAliases.ContainsKey(aliasName));
usingAliases[aliasName] = name;
// In C#, it's valid to declare two alias with identical name,
// as long as they are in different containers.
//
// e.g.
// using X = System.String;
// namespace N
// {
// using X = System.Int32;
// }
//
// If we detect this, we will simply treat extension methods whose
// target type is this alais as complex method.
if (usingAliases.ContainsKey(aliasName))
{
usingAliases[aliasName] = null;
}
else
{
usingAliases[aliasName] = name;
}
}
}
......@@ -288,19 +302,29 @@ internal sealed partial class SyntaxTreeIndex
return;
}
// complex type
// complex method
if (targetTypeName == null)
{
complexInfoBuilder.Add(declaredSymbolInfoIndex);
return;
}
// Target type is an alias
if (aliases.TryGetValue(targetTypeName, out var originalName))
{
// it is an alias of multiple with identical name,
// simply treat it as a complex method.
if (originalName == null)
{
complexInfoBuilder.Add(declaredSymbolInfoIndex);
return;
}
// replace the alias with its original name.
targetTypeName = originalName;
}
// simple type
// So we've got a simple method.
if (!simpleInfoBuilder.TryGetValue(targetTypeName, out var arrayBuilder))
{
arrayBuilder = ArrayBuilder<int>.GetInstance();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册