Patch 8.2.1287
Problem: Vim9: crash when using an imported function.
Solution: Add the function type to the imported entry. (closes #6522)
Files: src/vim9script.c, src/vim9compile.c,
src/testdir/test_vim9_script.vim
*** ../vim-8.2.1286/src/vim9script.c 2020-07-23 14:39:43.325828859 +0200
--- src/vim9script.c 2020-07-23 22:21:57.335980759 +0200
***************
*** 465,471 ****
--- 465,474 ----
imported->imp_var_vals_idx = idx;
}
else
+ {
+ imported->imp_type = ufunc->uf_func_type;
imported->imp_funcname = ufunc->uf_name;
+ }
}
}
erret:
*** ../vim-8.2.1286/src/vim9compile.c 2020-07-23 20:56:01.215470359 +0200
--- src/vim9compile.c 2020-07-23 22:36:19.964779715 +0200
***************
*** 714,720 ****
if (ga_grow(stack, 1) == FAIL)
return NULL;
! ((type_T **)stack->ga_data)[stack->ga_len] = type;
++stack->ga_len;
return isn;
--- 714,720 ----
if (ga_grow(stack, 1) == FAIL)
return NULL;
! ((type_T **)stack->ga_data)[stack->ga_len] = type == NULL ? &t_any : type;
++stack->ga_len;
return isn;
***************
*** 1178,1184 ****
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
return FAIL;
! isn->isn_arg.string = name;
return OK;
}
--- 1178,1184 ----
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
return FAIL;
! isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name);
return OK;
}
***************
*** 2807,2820 ****
idx,
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;
}
--- 2807,2819 ----
idx,
type);
}
+ else if (import->imp_funcname != NULL)
+ generate_PUSHFUNC(cctx, import->imp_funcname, import->imp_type);
else
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
import->imp_sid,
import->imp_var_vals_idx,
import->imp_type);
return OK;
}
***************
*** 2835,2842 ****
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);
}
/*
--- 2834,2840 ----
if (ufunc->uf_def_status == UF_TO_BE_COMPILED)
if (compile_def_function(ufunc, TRUE, NULL) == FAIL)
return FAIL;
! return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type);
}
/*
*** ../vim-8.2.1286/src/testdir/test_vim9_script.vim 2020-07-23 21:14:39.827891492 +0200
--- src/testdir/test_vim9_script.vim 2020-07-23 22:32:30.157663148 +0200
***************
*** 912,917 ****
--- 912,923 ----
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,935 ****
--- 936,942 ----
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'))
*** ../vim-8.2.1286/src/version.c 2020-07-23 21:14:39.827891492 +0200
--- src/version.c 2020-07-23 22:15:47.433158192 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1287,
/**/
--
hundred-and-one symptoms of being an internet addict:
78. You find yourself dialing IP numbers on the phone.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///