dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.96k stars 4.02k forks source link

Decide what support local functions should have in the EE #13181

Open agocke opened 8 years ago

agocke commented 8 years ago

Locals can currently be declared in the immediate window. Do we want to allow the same for local functions? What's the current state of local function support in the EE?

jaredpar commented 8 years ago

We should punt declaring local functions in EE windows. But it should be possible to invoke local functions from the EE.

agocke commented 8 years ago

Thanks to @gafter for doing a little exploration around captured variables in a local function:

Variables captured in local functions (and therefore in a struct closure) appear to work perfectly in the EE, including mutations. I tested by hand with the following code and it works.

using System;

class Program
{
    static void Main()
    {
        int x = 0, y = 0;
        int Local()
        {
            return (x = x + 1);
        }
        Local();
        // use EE to set x = 2 here
        // use EE to set x = 3 here
        Console.WriteLine(x); // should print 2
        Console.WriteLine(y); // should print 3
    }
}
gafter commented 8 years ago

My intuition is that a function declared in the EE should work like the scripting language extension. In other words, it should act like a top-level method. In a nested context it should "just work". But this also seems esoteric and unlikely to be missed by customers, so I recommend punting it to some indefinite future.

jcouv commented 7 years ago

@cston If you feel this will possibly involve a code change (not just tests), then please open a VSO tracking issue. Otherwise, let's mark this with Test label.

cston commented 7 years ago

The EE currently ignores local function members in the containing class so local functions are not callable in the EE.

tmat commented 7 years ago

The immediate window doesn't support multi-line snippets, nor does it support all statements. First, we need to replace the immediate window with interactive window and then we can extend the support to all statements (including local function declarations).

We should however implement invocation of local functions defined in the current method.

ivanbasov commented 7 years ago

Related to https://github.com/dotnet/roslyn/issues/16062

agocke commented 6 years ago

cc @AlekseyTs

Przemyslaw-W commented 4 years ago

Humble request to bump this up. I use many local functions in my code and I cannot call them in the watch window. This is becoming more and more painful every day.

jcouv commented 3 years ago

I've run into this as well. It's currently not possible to invoke a local function from the EE. That's quite unexpected.

waltdestler commented 3 years ago

Upvote and link to related Rider issue: https://youtrack.jetbrains.com/issue/RIDER-56176