Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 26053:e861c5aaedd8 v8.2.3560
patch 8.2.3560: using freed memory with lambda
Commit: https://github.com/vim/vim/commit/844fb64a605d60131827503a001b2d1aa232b078
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 23 13:32:30 2021 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 23 Oct 2021 14:45:04 +0200 |
parents | fe8d153cb268 |
children | a968027f8a2c |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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