未验证 提交 ef2ad433 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #45594 from CyrusNajmabadi/gotoDefNullable

Fix issue preventing going to def on a complicated metadata symbol involving nullability and generics
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.SymbolId
{
[UseExportProvider]
public class SymbolKeyTests
{
[Fact, WorkItem(45437, "https://github.com/dotnet/roslyn/issues/45437")]
public async Task TestGenericsAndNullability()
{
var typeSource = @"
#nullable enable
public sealed class ConditionalWeakTableTest<TKey, TValue> /*: IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable*/
where TKey : class
where TValue : class
{
public ConditionalWeakTable() { }
public void Add(TKey key, TValue value) { }
public void AddOrUpdate(TKey key, TValue value) { }
public void Clear() { }
public TValue GetOrCreateValue(TKey key) => default;
public TValue GetValue(TKey key, ConditionalWeakTableTest<TKey, TValue>.CreateValueCallback createValueCallback) => default;
public bool Remove(TKey key) => false;
public delegate TValue CreateValueCallback(TKey key);
}".Replace("<", "&lt;").Replace(">", "&gt;");
var workspaceXml = @$"
<Workspace>
<Project Language=""C#"">
<CompilationOptions Nullable=""Enable""/>
<Document FilePath=""C.cs"">
{typeSource}
</Document>
</Project>
</Workspace>
";
using var workspace = TestWorkspace.Create(workspaceXml);
var solution = workspace.CurrentSolution;
var project = solution.Projects.Single();
var compilation = await project.GetCompilationAsync();
var type = compilation.GetTypeByMetadataName("ConditionalWeakTableTest`2");
var method = type.GetMembers("GetValue").OfType<IMethodSymbol>().Single();
var callbackParamater = method.Parameters[1];
var parameterType = callbackParamater.Type;
Assert.Equal("global::ConditionalWeakTableTest<TKey!, TValue!>.CreateValueCallback!", parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier)));
var symbolKey = SymbolKey.Create(method);
var resolved = symbolKey.Resolve(compilation).Symbol;
Assert.Equal(method, resolved);
}
}
}
......@@ -344,8 +344,7 @@ private bool HandleNamedTypesWorker(INamedTypeSymbol x, INamedTypeSymbol y, Dict
{
Debug.Assert(GetTypeKind(x) == GetTypeKind(y));
if (x.IsDefinition != y.IsDefinition ||
IsConstructedFromSelf(x) != IsConstructedFromSelf(y) ||
if (IsConstructedFromSelf(x) != IsConstructedFromSelf(y) ||
x.Arity != y.Arity ||
x.Name != y.Name ||
x.IsAnonymousType != y.IsAnonymousType ||
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册