-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Vim9: cannot read closure variable in debug mode #9951
Comments
Unrelated, but why does adding a breakpoint on all lambda functions prevents Vim from finding a closure at compile time? vim9script
def Func()
var s = 'rep'
def Closure(): string
return s
enddef
echo 'text'->substitute('.*', () => Closure(), '')
enddef
breakadd func <lambda>*
Func()
No such error if we add a breakpoint on all functions: vim9script
def Func()
var s = 'rep'
def Closure(): string
return s
enddef
echo 'text'->substitute('.*', () => Closure(), '')
enddef
breakadd func *
Func() |
For the first problem: The compiled function knows where to find the value of the variable. However, the debug "echo" command has no clue where to find it. This would be quite difficult to make work. For the second problem: The closure is compiled without debugging when first encountering it. When it is later compiled for debugging the context is missing. I'll see if it can be compiled for debugging earlier. |
Now the help says this:
The last sentence seems to imply that there is a way to access variables from a closure in debug mode:
But it doesn't work. Test 1:
Test 2:
And yet, in both cases, the breakpoint is defined before calling or compiling any function. |
Now the help says this:
A closure must be compiled in the context that it is defined in, so that
variables in that context can be found. This mostly happens correctly, except
when a function is marked for debugging with `breakadd` after it was compiled.
Make sure to define the breakpoint before compiling the outer function.
The last sentence seems to imply that there is a way to access
variables from a closure in debug mode:
No, it means that if you add the breakpoint later, compiling the closure
may fail, because it cannot find the variables in the context. That's
even worse than not being able to print the variables.
You can work around it by assigning the value to a global variable, you
can print that. It does require changing the script temporarily.
…--
"My particular problem is with registry entries, which seem to just
accumulate like plastic coffee cups..." -- Paul Moore
/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
Steps to reproduce
Run this shell command:
Execute
>step
to step intoFunc()
.Execute
>next
to step overvar s = 'rep'
.Execute
>next
to step overdef Closure(): string
.Execute
>step
to step into the lambda() => Closure()
.Execute
>step
to step intoClosure()
.Finally, execute
>echo s
; an error is given:Expected behavior
No error is given because
s
is defined in the outer environment ofClosure()
, and the code works fine without:debug
:Version of Vim
8.2 Included patches: 1-4559
Environment
Operating system: Ubuntu 20.04.4 LTS
Terminal: xterm
Value of $TERM: xterm-256color
Shell: zsh 5.8
Additional context
At the script level, the exact same code does not give any error:
Although, in that case, we're no longer dealing with a closure...
The text was updated successfully, but these errors were encountered: