Skip to content

C#: Fix extraction of qualified delegate calls #15484

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

Merged

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 31, 2024

This PR fixes an extractor bug where we would incorrectly determine the qualifier of a delegate call when it was a qualified expression. For example, in

this.LambdaField(0)

where LambdaField is a field holding a lambda, we would consider this to be the qualifier of the delegate call, instead of this.LambdaField.

@github-actions github-actions bot added the C# label Jan 31, 2024
@hvitved hvitved force-pushed the csharp/qualified-delegate-extraction-fix branch from d74cac2 to c74bc68 Compare January 31, 2024 12:22
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jan 31, 2024
@hvitved hvitved marked this pull request as ready for review January 31, 2024 18:19
@hvitved hvitved requested a review from a team as a code owner January 31, 2024 18:19
michaelnebel
michaelnebel previously approved these changes Feb 1, 2024
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Looks good to me!
How/why did you discover this problem?

@@ -33,7 +37,7 @@ protected override void PopulateExpression(TextWriter trapFile)
var target = TargetSymbol;
switch (Syntax.Expression)
{
case MemberAccessExpressionSyntax memberAccess:
case MemberAccessExpressionSyntax memberAccess when Kind == ExprKind.METHOD_INVOCATION || IsEventDelegateCall() || IsExplicitDelegateInvokeCall():
Copy link
Contributor

Choose a reason for hiding this comment

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

When is this when condition not the same as Kind == ExprKind.METHOD_INVOCATION || Kind = ExprKind.DELEGATE_INVOCATION?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly when the member being accessed is not an event or a direct .Invoke, i.e., when it is a field or a property.


void M()
{
this.Field(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have the same problem with function pointers? (unsafe delegate*<int, void> Field2;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We did, yes, but that is also fixed by this PR. I have added additional tests to witness.

Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

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

LGTM

@hvitved hvitved merged commit 5080077 into github:main Feb 1, 2024
@hvitved hvitved deleted the csharp/qualified-delegate-extraction-fix branch February 1, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants