提交 c34025c9 编写于 作者: C Cyrus Najmabadi

Make check stricter.

上级 eb2acf36
......@@ -120,8 +120,21 @@ public async Task TestNotWithinNumericLiteral()
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestNotAfterAsync()
{
await VerifyAbsenceAsync(AddInsideMethod(
@"Goo(async $$"));
await VerifyAbsenceAsync(
@"
using System;
class C
{
void Goo()
{
Bar(async $$
}
void Bar(Func<int, string> f)
{
}
}");
}
}
}
......@@ -172,8 +172,21 @@ public async Task TestNotWithinNumericLiteral()
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestNotAfterAsync()
{
await VerifyAbsenceAsync(AddInsideMethod(
@"Goo(async $$"));
await VerifyAbsenceAsync(
@"
using System;
class C
{
void Goo()
{
Bar(async $$
}
void Bar(Func<int, string> f)
{
}
}");
}
}
}
......@@ -223,7 +223,7 @@ private static CSharpSyntaxContext CreateContextWorker(Workspace workspace, Sema
syntaxTree.IsLabelContext(position, cancellationToken),
syntaxTree.IsTypeArgumentOfConstraintClause(position, cancellationToken),
syntaxTree.IsRightOfDotOrArrowOrColonColon(position, cancellationToken),
syntaxTree.IsIsOrAsContext(position, leftToken, cancellationToken),
syntaxTree.IsIsOrAsContext(semanticModel, position, leftToken, cancellationToken),
syntaxTree.IsObjectCreationTypeContext(position, leftToken, cancellationToken),
syntaxTree.IsDefiniteCastTypeContext(position, leftToken, cancellationToken),
syntaxTree.IsGenericTypeArgumentContext(position, leftToken, cancellationToken),
......
......@@ -2546,7 +2546,10 @@ public static bool IsNameOfContext(this SyntaxTree syntaxTree, int position, Sem
return false;
}
public static bool IsIsOrAsContext(this SyntaxTree syntaxTree, int position, SyntaxToken tokenOnLeftOfPosition, CancellationToken cancellationToken)
public static bool IsIsOrAsContext(
this SyntaxTree syntaxTree, SemanticModel semanticModel,
int position, SyntaxToken tokenOnLeftOfPosition,
CancellationToken cancellationToken)
{
// cases:
// expr |
......@@ -2622,8 +2625,13 @@ public static bool IsIsOrAsContext(this SyntaxTree syntaxTree, int position, Syn
// async $$
//
// 'async' will look like a normal identifier. But we don't want to follow it
// with 'is' or 'as'.
return false;
// with 'is' or 'as' if it's actually the start of a lambda.
var delegateType = CSharpTypeInferenceService.Instance.InferDelegateType(
semanticModel, token.SpanStart, cancellationToken);
if (delegateType != null)
{
return false;
}
}
// Now, make sure the name was actually in a location valid for
......
......@@ -15,6 +15,8 @@ namespace Microsoft.CodeAnalysis.CSharp
[ExportLanguageService(typeof(ITypeInferenceService), LanguageNames.CSharp), Shared]
internal partial class CSharpTypeInferenceService : AbstractTypeInferenceService<ExpressionSyntax>
{
public static readonly CSharpTypeInferenceService Instance = new CSharpTypeInferenceService();
protected override AbstractTypeInferrer CreateTypeInferrer(SemanticModel semanticModel, CancellationToken cancellationToken)
{
return new TypeInferrer(semanticModel, cancellationToken);
......
......@@ -29,6 +29,21 @@ public static ImmutableArray<TypeInferenceInfo> GetTypeInferenceInfo(this ITypeI
CancellationToken cancellationToken)
{
var types = typeInferenceService.InferTypes(semanticModel, expression, cancellationToken);
return GetFirstDelegateType(semanticModel, types);
}
public static INamedTypeSymbol InferDelegateType(
this ITypeInferenceService typeInferenceService,
SemanticModel semanticModel,
int position,
CancellationToken cancellationToken)
{
var types = typeInferenceService.InferTypes(semanticModel, position, cancellationToken);
return GetFirstDelegateType(semanticModel, types);
}
private static INamedTypeSymbol GetFirstDelegateType(SemanticModel semanticModel, ImmutableArray<ITypeSymbol> types)
{
var delegateTypes = types.Select(t => t.GetDelegateType(semanticModel.Compilation));
return delegateTypes.WhereNotNull().FirstOrDefault();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册