summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-23 22:41:43 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-23 22:41:43 +0200
commit40f4f7a48cae491f83bd3cdbf7e9b5a23ed870ef (patch)
tree877d3dba233503a446f13f7315bd4e29579177cc
parent43e969d3f98766824c18d20b84f2fab00feef683 (diff)
patch 8.2.1287: Vim9: crash when using an imported functionv8.2.1287
Problem: Vim9: crash when using an imported function. Solution: Add the function type to the imported entry. (closes #6522)
-rw-r--r--src/testdir/test_vim9_script.vim7
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c12
-rw-r--r--src/vim9script.c3
4 files changed, 17 insertions, 7 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index d7464856b3..3e2ced0a93 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -912,6 +912,12 @@ def Test_vim9_import_export()
g:imported_added = exported
g:imported_func = Exported()
+ def GetExported(): string
+ let local_dict = #{ref: Exported}
+ return local_dict.ref()
+ enddef
+ g:funcref_result = GetExported()
+
import {exp_name} from './Xexport.vim'
g:imported_name = exp_name
exp_name ..= ' Doe'
@@ -930,6 +936,7 @@ def Test_vim9_import_export()
assert_equal(9879, g:imported_added)
assert_equal(9879, g:imported_later)
assert_equal('Exported', g:imported_func)
+ assert_equal('Exported', g:funcref_result)
assert_equal('John', g:imported_name)
assert_equal('John Doe', g:imported_name_appended)
assert_false(exists('g:name'))
diff --git a/src/version.c b/src/version.c
index fc86f15dc2..8f8ebc6ff8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1287,
+/**/
1286,
/**/
1285,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 52841de6bd..53bfb6c48e 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -714,7 +714,7 @@ generate_instr_type(cctx_T *cctx, isntype_T isn_type, type_T *type)
if (ga_grow(stack, 1) == FAIL)
return NULL;
- ((type_T **)stack->ga_data)[stack->ga_len] = type;
+ ((type_T **)stack->ga_data)[stack->ga_len] = type == NULL ? &t_any : type;
++stack->ga_len;
return isn;
@@ -1178,7 +1178,7 @@ generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
return FAIL;
- isn->isn_arg.string = name;
+ isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name);
return OK;
}
@@ -2807,14 +2807,13 @@ compile_load_scriptvar(
idx,
type);
}
+ else if (import->imp_funcname != NULL)
+ generate_PUSHFUNC(cctx, import->imp_funcname, import->imp_type);
else
- {
- // TODO: check this is a variable, not a function?
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
import->imp_sid,
import->imp_var_vals_idx,
import->imp_type);
- }
return OK;
}
@@ -2835,8 +2834,7 @@ generate_funcref(cctx_T *cctx, char_u *name)
if (ufunc->uf_def_status == UF_TO_BE_COMPILED)
if (compile_def_function(ufunc, TRUE, NULL) == FAIL)
return FAIL;
- return generate_PUSHFUNC(cctx, vim_strsave(ufunc->uf_name),
- ufunc->uf_func_type);
+ return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type);
}
/*
diff --git a/src/vim9script.c b/src/vim9script.c
index 34c3dabcf0..784283ef97 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -465,7 +465,10 @@ handle_import(
imported->imp_var_vals_idx = idx;
}
else
+ {
+ imported->imp_type = ufunc->uf_func_type;
imported->imp_funcname = ufunc->uf_name;
+ }
}
}
erret: