Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest where keyword in generic local function declarations #72838

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -631,5 +631,46 @@ public class C<T> where T : List<(int, string)> $$
}
""");
}

[Fact]
sharwell marked this conversation as resolved.
Show resolved Hide resolved
public async Task TestNotAfterLocalFunction()
{
await VerifyAbsenceAsync(
"""
class C
{
void M<T>()
{
void Inner() $$
""");
}

[Fact]
sharwell marked this conversation as resolved.
Show resolved Hide resolved
public async Task TestAfterGenericLocalFunction()
{
await VerifyKeywordAsync(
"""
class C
{
void M<T>()
{
void Inner<T1>() $$
""");
}

[Fact]
sharwell marked this conversation as resolved.
Show resolved Hide resolved
public async Task TestAfterFirstValidConstraintInGenericLocalFunction()
{
await VerifyKeywordAsync(
"""
class C
{
void M<T>()
{
void Inner<T1, T2>()
where T1 : C
$$
""");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,24 @@ private static bool IsTypeParameterConstraintContext(CSharpSyntaxContext context
// void Goo<T>() |

if (token.Kind() == SyntaxKind.CloseParenToken &&
token.Parent.IsKind(SyntaxKind.ParameterList) &&
token.Parent.IsParentKind(SyntaxKind.MethodDeclaration))
token.Parent.IsKind(SyntaxKind.ParameterList))
{
var decl = token.GetAncestor<MethodDeclarationSyntax>();
if (decl != null && decl.Arity > 0)
var tokenParent = token.Parent;
if (tokenParent.IsParentKind(SyntaxKind.MethodDeclaration))
sharwell marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
var decl = token.GetAncestor<MethodDeclarationSyntax>();
if (decl != null && decl.Arity > 0)
{
return true;
}
}
else if (tokenParent.IsParentKind(SyntaxKind.LocalFunctionStatement))
{
var decl = token.GetAncestor<LocalFunctionStatementSyntax>();
if (decl is { TypeParameterList.Parameters.Count: > 0 })
{
return true;
}
}
}

Expand Down
Loading