Skip to content

Ensure local function invocations and method references always have null receivers #56395

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

333fred
Copy link
Member

@333fred 333fred commented Sep 14, 2021

Fixes #51715.

@333fred 333fred requested a review from a team as a code owner September 14, 2021 23:23
@333fred
Copy link
Member Author

333fred commented Sep 15, 2021

@AlekseyTs, so it turns out that the IDE is depending on the current behavior of IOperation here, as the bootstrap build is now failing.

@AlekseyTs
Copy link
Contributor

so it turns out that the IDE is depending on the current behavior of IOperation here, as the bootstrap build is now failing.

It feels like that (IDE) should be fixed.


// Local functions are not invoked on receivers from a language point of view, and thus we do not expose
// a receiver for them.
if (symbol is MethodSymbol { MethodKind: MethodKind.LocalFunction })
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 16, 2021

Choose a reason for hiding this comment

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

if (symbol is MethodSymbol { MethodKind: MethodKind.LocalFunction })

Would it be better to adjust binding so that it wouldn't add a receiver? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we are doing this for regular static methods too

[Theory, WorkItem(51715, "https://github.com/dotnet/roslyn/issues/51715")]
[InlineData("static")]
[InlineData("")]
public void Invocation_LocalFunction_01(string modifier)
Copy link
Contributor

Choose a reason for hiding this comment

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

Invocation_LocalFunction_01

It looks like all the tests are testing scenarios within an implicit static method. Consider testing inside a regular instance method and, perhaps, a regular static method as well.

@@ -305,5 +305,89 @@ void M(C c1, C c2, System.Func<int> m1, System.Func<int> m2)

VerifyFlowGraphAndDiagnosticsForTest<BlockSyntax>(source, expectedFlowGraph, expectedDiagnostics);
}

[Fact, WorkItem(51715, "https://github.com/dotnet/roslyn/issues/51715")]
public void MethodReference_LocalFunction_01()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for the invocation tests.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 1), modulo suggested additional tests

@333fred 333fred added this to the 17.1 milestone Sep 20, 2021
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 1)

@jcouv jcouv self-assigned this Sep 30, 2021
@jcouv jcouv marked this pull request as draft March 15, 2022 17:30
@jinujoseph jinujoseph modified the milestones: 17.1, 17.3 Apr 27, 2022
@arunchndr arunchndr modified the milestones: 17.3, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IMethodReferenceOperation for local function within static method should have a separate InstanceReferenceKind
5 participants