patch 9.2.1172: Vim9: crash when lambda assigns to item of outer argument
Problem: Assigning to an element of an outer function's argument inside
a lambda causes a crash when the lambda is called.
Solution: When an outer function's argument is found on the left-hand
side of an assignment, record that the outer scope is used and
treat the lambda as a closure.
When an outer function's argument was used on the left-hand side of an
assignment, a LOADOUTER instruction was generated, but the lambda was
not treated as a closure. Consequently, the outer stack was not set for
the partial, leading to a NULL reference during the execution of
LOADOUTER.
fixes: #21460
closes: #21465
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
1 parent
ec130c0fd9
commit
b2b47bdf94
3 files changed
+45
No files matched your search
@@ -3142,6 +3142,46 @@ def Test_closure_using_argument()
|
||||
assert_equal([3, 4, 5], Test(Inc))
|
||||
END
|
||||
v9.CheckScriptSuccess(lines)
|
||||
|
||||
# assign to an element of the outer function's argument
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def MakeSetter(arg: dict<any>): func()
|
||||
return () => {
|
||||
arg.key = 1
|
||||
}
|
||||
enddef
|
||||
def Run()
|
||||
var Set = MakeSetter({})
|
||||
Set()
|
||||
enddef
|
||||
Run()
|
||||
|
||||
var d: dict<any> = {}
|
||||
MakeSetter(d)()
|
||||
assert_equal({key: 1}, d)
|
||||
|
||||
def MakeListSetter(arg: list<number>): func()
|
||||
return () => {
|
||||
arg[0] = 2
|
||||
}
|
||||
enddef
|
||||
var l = [0]
|
||||
MakeListSetter(l)()
|
||||
assert_equal([2], l)
|
||||
|
||||
def MakeNestedSetter(arg: dict<any>): func(): func()
|
||||
return () => {
|
||||
return () => {
|
||||
arg.key = 3
|
||||
}
|
||||
}
|
||||
enddef
|
||||
var nd: dict<any> = {}
|
||||
MakeNestedSetter(nd)()()
|
||||
assert_equal({key: 3}, nd)
|
||||
END
|
||||
v9.CheckScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
def s:MakeGetAndAppendRefs()
|
||||
|
||||
@@ -743,6 +743,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1172,
|
||||
/**/
|
||||
1171,
|
||||
/**/
|
||||
|
||||
@@ -183,7 +183,10 @@ arg_exists(
|
||||
== OK)
|
||||
{
|
||||
if (gen_load_outer != NULL)
|
||||
{
|
||||
++*gen_load_outer;
|
||||
cctx->ctx_outer_used = TRUE;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user