Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
26052:351359bff011 | 26053:e861c5aaedd8 |
---|---|
1127 | 1127 |
1128 def g:TestFunc(f: func(number)) | 1128 def g:TestFunc(f: func(number)) |
1129 enddef | 1129 enddef |
1130 legacy call g:TestFunc({nr -> 0}) | 1130 legacy call g:TestFunc({nr -> 0}) |
1131 delfunc g:TestFunc | 1131 delfunc g:TestFunc |
1132 END | |
1133 CheckScriptSuccess(lines) | |
1134 enddef | |
1135 | |
1136 def Test_lambda_in_reduce_line_break() | |
1137 # this was using freed memory | |
1138 var lines =<< trim END | |
1139 vim9script | |
1140 const result: dict<number> = | |
1141 ['Bob', 'Sam', 'Cat', 'Bob', 'Cat', 'Cat'] | |
1142 ->reduce((acc, val) => { | |
1143 if has_key(acc, val) | |
1144 acc[val] += 1 | |
1145 return acc | |
1146 else | |
1147 acc[val] = 1 | |
1148 return acc | |
1149 endif | |
1150 }, {}) | |
1151 assert_equal({Bob: 2, Sam: 1, Cat: 3}, result) | |
1132 END | 1152 END |
1133 CheckScriptSuccess(lines) | 1153 CheckScriptSuccess(lines) |
1134 enddef | 1154 enddef |
1135 | 1155 |
1136 " Default arg and varargs | 1156 " Default arg and varargs |