未验证 提交 53421f42 编写于 作者: G Gen Lu 提交者: GitHub

Merge pull request #47857 from genlu/InferFirstArgumentType

Enter suggestion mode for potential lambda expression
......@@ -1349,6 +1349,58 @@ void M(C test)
await VerifyNotBuilderAsync(markup);
}
[WorkItem(46927, "https://github.com/dotnet/roslyn/issues/46927")]
[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task FirstArgumentOfInvocation_NoParameter(bool hasTypedChar)
{
var markup = $@"
using System;
interface Foo
{{
bool Bar() => true;
}}
class P
{{
void M(Foo f)
{{
f.Bar({(hasTypedChar ? "s" : "")}$$
}}
}}";
await VerifyNotBuilderAsync(markup);
}
[WorkItem(46927, "https://github.com/dotnet/roslyn/issues/46927")]
[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task FirstArgumentOfInvocation_PossibleLambdaExpression(bool isLambda, bool hasTypedChar)
{
var overload = isLambda
? "bool Bar(Func<int, bool> predicate) => true;"
: "bool Bar(int x) => true;";
var markup = $@"
using System;
interface Foo
{{
bool Bar() => true;
{overload}
}}
class P
{{
void M(Foo f)
{{
f.Bar({(hasTypedChar ? "s" : "")}$$
}}
}}";
if (isLambda)
{
await VerifyBuilderAsync(markup);
}
else
{
await VerifyNotBuilderAsync(markup);
}
}
private async Task VerifyNotBuilderAsync(string markup)
=> await VerifyWorkerAsync(markup, isBuilder: false);
......
......@@ -458,10 +458,13 @@ private IEnumerable<TypeInferenceInfo> InferTypeInObjectCreationExpression(BaseO
var info = SemanticModel.GetSymbolInfo(invocation, CancellationToken);
var methods = info.GetBestOrAllSymbols().OfType<IMethodSymbol>();
// Overload resolution (see DevDiv 611477) in certain extension method cases
// can result in GetSymbolInfo returning nothing. In this case, get the
// method group info, which is what signature help already does.
if (info.Symbol == null)
// 1. Overload resolution (see DevDiv 611477) in certain extension method cases
// can result in GetSymbolInfo returning nothing.
// 2. when trying to infer the type of the first argument, it's possible that nothing corresponding to
// the argument is typed and there exists an overload with 0 parameter as a viable match.
// In one of these cases, get the method group info, which is what signature help already does.
if (info.Symbol == null ||
argumentOpt == null && info.Symbol is IMethodSymbol method && method.Parameters.Length == 0)
{
var memberGroupMethods =
SemanticModel.GetMemberGroup(invocation.Expression, CancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册