Skip to content
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 @@ -28,4 +28,13 @@ class Test {
unsafe void N() {
delegate*$$
""");

[Fact]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use [Fact, WorkItem("...")]. Also, test the specific case i n the original bug, where the function pointer type was being written inside a cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a9e5e87. Added WorkItem attribute and test for the cast expression case from the original bug report.

public Task TestInFunctionPointerDeclarationAfterTyping()
=> VerifyKeywordAsync(
"""
class Test {
unsafe void N() {
delegate*manag$$
""");
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,13 @@ class Test {
unsafe void N() {
delegate*$$
""");

[Fact]
public Task TestInFunctionPointerDeclarationAfterTyping()
=> VerifyKeywordAsync(
"""
class Test {
unsafe void N() {
delegate*unman$$
""");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3070,8 +3070,18 @@ public static bool IsEnumTypeMemberAccessContext(this SyntaxTree syntaxTree, Sem

public static bool IsFunctionPointerCallingConventionContext(this SyntaxTree syntaxTree, SyntaxToken targetToken)
{
return targetToken.IsKind(SyntaxKind.AsteriskToken) &&
targetToken.Parent is FunctionPointerTypeSyntax functionPointerType &&
targetToken == functionPointerType.AsteriskToken;
// Check if we're at or after delegate*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot you just need to check that the target token is an asterix, and the .GetPreviousToken() from it is the delegate keyword. That's all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a9e5e87. Simplified to just check that targetToken is an asterisk and the previous token is the delegate keyword.

if (targetToken.IsKind(SyntaxKind.AsteriskToken) &&
targetToken.Parent is FunctionPointerTypeSyntax functionPointerType &&
targetToken == functionPointerType.AsteriskToken)
{
return true;
}

// Check if the previous token is the asterisk (handles typing after delegate*)
var previousToken = targetToken.GetPreviousToken();
return previousToken.IsKind(SyntaxKind.AsteriskToken) &&
previousToken.Parent is FunctionPointerTypeSyntax functionPointerType2 &&
previousToken == functionPointerType2.AsteriskToken;
}
}
Loading