diff src/evalvars.c @ 22942:4759d13193fb v8.2.2018

patch 8.2.2018: Vim9: script variable not found from lambda Commit: https://github.com/vim/vim/commit/2ea95b61f4bec9b71cf916eebe8d11abc76617a0 Author: Bram Moolenaar <Bram@vim.org> 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 19 Nov 2020 22:00:05 +0100
parents 3e0f909ca1f2
children ad674a98058a
line wrap: on
line diff
--- 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;
 }
 
 /*