diff src/evalvars.c @ 21206:caab594592cc v8.2.1154

patch 8.2.1154: Vim9: crash when using imported function Commit: https://github.com/vim/vim/commit/c620c055ce8505596a7208ba696a32b8a3be4f4b Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jul 8 15:16:19 2020 +0200 patch 8.2.1154: Vim9: crash when using imported function Problem: Vim9: crash when using imported function. Solution: Check for a function type. Set the script context when calling a function. (closes #6412)
author Bram Moolenaar <Bram@vim.org>
date Wed, 08 Jul 2020 15:30:04 +0200
parents 951aad18b1af
children 6a4806e326dd
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2375,6 +2375,7 @@ eval_variable(
 {
     int		ret = OK;
     typval_T	*tv = NULL;
+    int		foundFunc = FALSE;
     dictitem_T	*v;
     int		cc;
 
@@ -2402,21 +2403,36 @@ eval_variable(
 	// imported variable from another script
 	if (import != NULL)
 	{
-	    scriptitem_T    *si = SCRIPT_ITEM(import->imp_sid);
-	    svar_T	    *sv = ((svar_T *)si->sn_var_vals.ga_data)
+	    if (import->imp_funcname != NULL)
+	    {
+		foundFunc = TRUE;
+		if (rettv != NULL)
+		{
+		    rettv->v_type = VAR_FUNC;
+		    rettv->vval.v_string = vim_strsave(import->imp_funcname);
+		}
+	    }
+	    else
+	    {
+		scriptitem_T    *si = SCRIPT_ITEM(import->imp_sid);
+		svar_T	    *sv = ((svar_T *)si->sn_var_vals.ga_data)
 						    + import->imp_var_vals_idx;
-	    tv = sv->sv_tv;
+		tv = sv->sv_tv;
+	    }
 	}
     }
 
-    if (tv == NULL)
+    if (!foundFunc)
     {
-	if (rettv != NULL && verbose)
-	    semsg(_(e_undefvar), name);
-	ret = FAIL;
+	if (tv == NULL)
+	{
+	    if (rettv != NULL && verbose)
+		semsg(_(e_undefvar), name);
+	    ret = FAIL;
+	}
+	else if (rettv != NULL)
+	    copy_tv(tv, rettv);
     }
-    else if (rettv != NULL)
-	copy_tv(tv, rettv);
 
     name[len] = cc;