diff src/evalvars.c @ 27924:e6e3abc28c7a v8.2.4487

patch 8.2.4487: Vim9: cannot compare with v:null Commit: https://github.com/vim/vim/commit/7a2222487507eb13cccdb9a66397092775d62b8c Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 1 19:23:24 2022 +0000 patch 8.2.4487: Vim9: cannot compare with v:null Problem: Vim9: cannot compare with v:null. Solution: Allow comparing anything with v:null. (closes https://github.com/vim/vim/issues/9866)
author Bram Moolenaar <Bram@vim.org>
date Tue, 01 Mar 2022 20:30:04 +0100
parents 27956f5e263c
children c8d6c2736796
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2816,29 +2816,33 @@ eval_variable(
 	    }
 
 	    // If a list or dict variable wasn't initialized, do it now.
-	    if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL)
-	    {
-		tv->vval.v_dict = dict_alloc();
-		if (tv->vval.v_dict != NULL)
-		{
-		    ++tv->vval.v_dict->dv_refcount;
-		    tv->vval.v_dict->dv_type = alloc_type(type);
-		}
-	    }
-	    else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL)
+	    // Not for global variables, they are not declared.
+	    if (ht != &globvarht)
 	    {
-		tv->vval.v_list = list_alloc();
-		if (tv->vval.v_list != NULL)
+		if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL)
 		{
-		    ++tv->vval.v_list->lv_refcount;
-		    tv->vval.v_list->lv_type = alloc_type(type);
+		    tv->vval.v_dict = dict_alloc();
+		    if (tv->vval.v_dict != NULL)
+		    {
+			++tv->vval.v_dict->dv_refcount;
+			tv->vval.v_dict->dv_type = alloc_type(type);
+		    }
 		}
-	    }
-	    else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL)
-	    {
-		tv->vval.v_blob = blob_alloc();
-		if (tv->vval.v_blob != NULL)
-		    ++tv->vval.v_blob->bv_refcount;
+		else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL)
+		{
+		    tv->vval.v_list = list_alloc();
+		    if (tv->vval.v_list != NULL)
+		    {
+			++tv->vval.v_list->lv_refcount;
+			tv->vval.v_list->lv_type = alloc_type(type);
+		    }
+		}
+		else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL)
+		{
+		    tv->vval.v_blob = blob_alloc();
+		    if (tv->vval.v_blob != NULL)
+			++tv->vval.v_blob->bv_refcount;
+		}
 	    }
 	    copy_tv(tv, rettv);
 	}