提交 8f8a6195 编写于 作者: A AlekseyTs

Merge pull request #5952 from AlekseyTs/Issue2544

Preserve LookupResult methods in a BoundMethodGroup even if they are not viable.
......@@ -4753,7 +4753,7 @@ private BoundExpression MakeMemberAccessValue(BoundExpression expr, DiagnosticBa
typeArguments,
boundLeft,
rightName,
ImmutableArray<MethodSymbol>.Empty,
lookupResult.Symbols.All(s => s.Kind == SymbolKind.Method) ? lookupResult.Symbols.SelectAsArray(s_toMethodSymbolFunc) : ImmutableArray<MethodSymbol>.Empty,
lookupResult,
flags);
}
......
......@@ -1987,6 +1987,18 @@ static void Main()
";
var compilation = CreateCompilationWithMscorlib(source);
compilation.VerifyDiagnostics(
// (5,14): error CS0535: 'Base' does not implement interface member 'IEnumerable<int>.GetEnumerator()'
// class Base : IEnumerable<int>
Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "IEnumerable<int>").WithArguments("Base", "System.Collections.Generic.IEnumerable<int>.GetEnumerator()").WithLocation(5, 14),
// (5,14): error CS0535: 'Base' does not implement interface member 'IEnumerable.GetEnumerator()'
// class Base : IEnumerable<int>
Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "IEnumerable<int>").WithArguments("Base", "System.Collections.IEnumerable.GetEnumerator()").WithLocation(5, 14),
// (17,32): error CS0122: 'X.Add(string)' is inaccessible due to its protection level
// var z = new X { String.Empty };
Diagnostic(ErrorCode.ERR_BadAccess, "Empty").WithArguments("X.Add(string)").WithLocation(17, 32)
);
var tree = compilation.SyntaxTrees.Single();
var semanticModel = compilation.GetSemanticModel(tree);
......@@ -1999,8 +2011,8 @@ where node.IsKind(SyntaxKind.CollectionInitializerExpression)
symbolInfo = semanticModel.GetCollectionInitializerSymbolInfo(nodes[0]);
Assert.Null(symbolInfo.Symbol);
Assert.Equal(CandidateReason.None, symbolInfo.CandidateReason);
Assert.Equal(0, symbolInfo.CandidateSymbols.Length);
Assert.Equal(CandidateReason.Inaccessible, symbolInfo.CandidateReason);
Assert.Equal("void X.Add(System.String x)", symbolInfo.CandidateSymbols.Single().ToTestDisplayString());
}
[WorkItem(529787, "DevDiv")]
......
......@@ -8237,5 +8237,47 @@ public static class Class
RemoveDetail
RemoveDetail");
}
[Fact, WorkItem(2544, "https://github.com/dotnet/roslyn/issues/2544")]
public void GetSymbolOnfo_Inaccessible()
{
var source =
@"
class C
{
private void M(D d)
{
d.M(1);
}
}
class D
{
private void M(int i) { }
private void M(double d) { }
}
";
var compilation = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseDll);
compilation.VerifyDiagnostics(
// (6,11): error CS0122: 'D.M(int)' is inaccessible due to its protection level
// d.M(1);
Diagnostic(ErrorCode.ERR_BadAccess, "M").WithArguments("D.M(int)").WithLocation(6, 11)
);
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var callSyntax = tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().Single();
var symbolInfo = model.GetSymbolInfo(callSyntax);
Assert.Equal(CandidateReason.Inaccessible, symbolInfo.CandidateReason);
var candidates = symbolInfo.CandidateSymbols;
Assert.Equal(2, candidates.Length);
Assert.Equal("void D.M(System.Int32 i)", candidates[0].ToTestDisplayString());
Assert.Equal("void D.M(System.Double d)", candidates[1].ToTestDisplayString());
}
}
}
......@@ -891,7 +891,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
End Sub
<WorkItem(2544, "https://github.com/dotnet/roslyn/issues/2544")>
<WpfFact(Skip:="2544"), Trait(Traits.Feature, Traits.Features.FindReferences)>
<WpfFact, Trait(Traits.Feature, Traits.Features.FindReferences)>
Public Sub TestInaccessibleMemberOverrideCS()
Dim workspace =
<Workspace>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册