# HG changeset patch # User Bram Moolenaar # Date 1605819605 -3600 # Node ID 4759d13193fb327f1294655d64400f19f332732d # Parent 2aa5ad6cb21c1bd5dfa4c3d5f27e5579e1ef3462 patch 8.2.2018: Vim9: script variable not found from lambda Commit: https://github.com/vim/vim/commit/2ea95b61f4bec9b71cf916eebe8d11abc76617a0 Author: Bram Moolenaar Date: Thu Nov 19 21:47:56 2020 +0100 patch 8.2.2018: Vim9: script variable not found from lambda Problem: Vim9: script variable not found from lambda. Solution: In a lambda also check the script hashtab for a variable without a scope. (closes #7329) diff --git a/src/evalvars.c b/src/evalvars.c --- a/src/evalvars.c +++ b/src/evalvars.c @@ -2628,7 +2628,28 @@ find_var(char_u *name, hashtab_T **htp, return ret; // Search in parent scope for lambda - return find_var_in_scoped_ht(name, no_autoload || htp != NULL); + ret = find_var_in_scoped_ht(name, no_autoload || htp != NULL); + if (ret != NULL) + return ret; + + // in Vim9 script items without a scope can be script-local + if (in_vim9script() && name[0] != NUL && name[1] != ':') + { + ht = get_script_local_ht(); + if (ht != NULL) + { + ret = find_var_in_ht(ht, *name, varname, + no_autoload || htp != NULL); + if (ret != NULL) + { + if (htp != NULL) + *htp = ht; + return ret; + } + } + } + + return NULL; } /* diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -1476,6 +1476,15 @@ def Test_line_continuation_in_def() Line_continuation_in_def('.')->assert_equal('full') enddef +def Test_script_var_in_lambda() + var lines =<< trim END + vim9script + var script = 'test' + assert_equal(['test'], map(['one'], {-> script})) + END + CheckScriptSuccess(lines) +enddef + def Line_continuation_in_lambda(): list var x = range(97, 100) ->map({_, v -> nr2char(v) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2018, +/**/ 2017, /**/ 2016,