dotnet / dotnet/fsharp

Uncaptured locals are not available in closures when debugging

Open
#11,262 2 comments 1 reaction 0 assignees View on GitHub
Area-Debug Feature Improvement Impact-Medium Theme-Simple-F#
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Repro:

1. Open VisualFSharp.sln
2. Open SignatureHelp.fs
3. Put a breakoint on line 123(`let startOfArgs = ...`)
4. Launch a hive of VS where you can debug
5. Enter the following source code:

```fsharp
type C() =
static member M(x, y, z) = ()

C.M(1)
```

6. Place cursor after the `1` on the last line
7. Press the comma character (`,`) so that Signature Help is triggered

Note that there are some locals, and critically you can observe the value of `applicableSpan`:

![image](https://user-images.githubusercontent.com/6309070/111529197-1a4e3100-871f-11eb-9202-f91d4e7f261c.png)

Now try to get the source code that matches this span by:

1. Opening the Immediate Window
2. Entering the following:

`sourceText.GetSubText(applicableSpan)`

You will observe that `sourceText` doesn't exist. Indeed, it wasn't even in the locals window.

![image](https://user-images.githubusercontent.com/6309070/111529367-4e295680-871f-11eb-93f8-d05e810b319a.png)

However, note that `sourceText` is a parameter to this method and it is clearly accessible.

We are losing debug info on every `do!` call in the method.

To test this, place a breakpoint on line 89 (`do! Option.guard (methods.Length > 0 ...`). When it is broken there, you'll see that `sourceText` is available:

![image](https://user-images.githubusercontent.com/6309070/111529603-96487900-871f-11eb-954d-2916ac5eb7d5.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.