Roslyn: Completion for `this` is always offered in anonymous functions

Created on 15 Jun 2018  路  9Comments  路  Source: dotnet/roslyn

```c#
using System;

class Foo
{
static void M()
{
Action a = () =>
{
$$
};

    Action b = delegate
    {
        $$
    };
}

}
`` In both places at$$,this` keyword is offered even though the method is static.

Discovered here:
https://github.com/dotnet/roslyn/pull/27690#pullrequestreview-128730842

I believe the fix should be really easy - just modify method.MethodKind == MethodKind.LocalFunction to method.MethodKind == MethodKind.LocalFunction || method.MethodKind == MethodKind.AnonymousFunction and add appropriate tests including nested anonymous functions and possibly even cases with a lambda inside a local function and vice versa, if you want to be extra diligent :smile:

3 - Working Area-IDE Bug good first issue

All 9 comments

Would marking this as "help wanted" or "good first issue" be appropriate?

Done. Thanks for catching and filing this

I would like to take up this issue as my first contribution to this project if possible.

Nice. Go for it.
The linked issue should be a guide (it fixed local functions, but missed anonymous functions).

@nprad Are you still interested in fixing this? Do you need any help?

I apologize for the delay on this. Yes, I'm still interested in contributing to this ticket. I'll try to have a PR by the end of the weekend if that okay with you.

No need to apologize. This is a very minor and low-priority issue, so you don't have to hurry. Yes it is okay with me (though I'm just a contributor, so whether or not it is ok with me is not really relevant, but I'm pretty sure the team is ok with that too :smile:)

This "issue" could be sitting here for years and noone would care, so you can take your time I think 馃槂 I reported it because I found this during code review, not because it is important to me.

I submitted a PR for this issue last night, not realising there is already one outstanding. The other PR doesn't currently pass the build, so I'll leave mine open. I'm happy to close it off if needed though.

Was this page helpful?
0 / 5 - 0 ratings