diff src/vim9script.c @ 28231:66b245d84f37 v8.2.4642

patch 8.2.4642: Vim9: in :def function script var cannot be null Commit: https://github.com/vim/vim/commit/859cc21c6b60af07b549456b7d050a03b3e48bc9 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 28 15:22:35 2022 +0100 patch 8.2.4642: Vim9: in :def function script var cannot be null Problem: Vim9: in :def function script var cannot be null. Solution: Only initialize a script variable when not set to a null value. (closes #10034)
author Bram Moolenaar <Bram@vim.org>
date Mon, 28 Mar 2022 16:30:03 +0200
parents b0b712d48225
children 4b322951ebac
line wrap: on
line diff
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -822,7 +822,7 @@ vim9_declare_scriptvar(exarg_T *eap, cha
 	init_tv.v_type = VAR_NUMBER;
     else
 	init_tv.v_type = type->tt_type;
-    set_var_const(name, 0, type, &init_tv, FALSE, 0, 0);
+    set_var_const(name, 0, type, &init_tv, FALSE, ASSIGN_INIT, 0);
 
     vim_free(name);
     return p;
@@ -925,6 +925,13 @@ update_vim9_script_var(
 	if (*type == NULL)
 	    *type = typval2type(tv, get_copyID(), &si->sn_type_list,
 					       do_member ? TVTT_DO_MEMBER : 0);
+	else if ((flags & ASSIGN_INIT) == 0
+		&& (*type)->tt_type == VAR_BLOB && tv->v_type == VAR_BLOB
+						    && tv->vval.v_blob == NULL)
+	{
+	    // "var b: blob = null_blob" has a different type.
+	    *type = &t_blob_null;
+	}
 	if (sv->sv_type_allocated)
 	    free_type(sv->sv_type);
 	if (*type != NULL && ((*type)->tt_type == VAR_FUNC