1
0
forked from aniani/vim

patch 8.2.3560: using freed memory with lambda

Problem:    Using freed memory with lambda.
Solution:   Do not free lines early, keep them until the expression is
            finished.
This commit is contained in:
Bram Moolenaar
2021-10-23 13:32:30 +01:00
parent ee56f3f119
commit 844fb64a60
8 changed files with 63 additions and 20 deletions

View File

@@ -1133,6 +1133,26 @@ def Test_pass_legacy_lambda_to_def_func()
CheckScriptSuccess(lines)
enddef
def Test_lambda_in_reduce_line_break()
# this was using freed memory
var lines =<< trim END
vim9script
const result: dict<number> =
['Bob', 'Sam', 'Cat', 'Bob', 'Cat', 'Cat']
->reduce((acc, val) => {
if has_key(acc, val)
acc[val] += 1
return acc
else
acc[val] = 1
return acc
endif
}, {})
assert_equal({Bob: 2, Sam: 1, Cat: 3}, result)
END
CheckScriptSuccess(lines)
enddef
" Default arg and varargs
def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
var res = one .. ',' .. two