Open agocke opened 8 years ago
We should punt declaring local functions in EE windows. But it should be possible to invoke local functions from the EE.
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
}
}
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.
@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.
The EE currently ignores local function members in the containing class so local functions are not callable in the EE.
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.
cc @AlekseyTs
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.
I've run into this as well. It's currently not possible to invoke a local function from the EE. That's quite unexpected.
Upvote and link to related Rider issue: https://youtrack.jetbrains.com/issue/RIDER-56176
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?