diff src/eval.c @ 22529:35ef9b0a81a3 v8.2.1813

patch 8.2.1813: Vim9: can assign wrong type to script dict Commit: https://github.com/vim/vim/commit/10c65860f83589e0ca2498393d3cfef1115b7fe8 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 8 21:16:42 2020 +0200 patch 8.2.1813: Vim9: can assign wrong type to script dict Problem: Vim9: can assign wrong type to script dict. (Christian J. Robinson) Solution: Check the type if known.
author Bram Moolenaar <Bram@vim.org>
date Thu, 08 Oct 2020 21:30:03 +0200
parents ef8a3177edc1
children 7d6ba4204f66
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -887,6 +887,17 @@ get_lval(
 	    return NULL;
 	}
 
+	if (in_vim9script() && lp->ll_valtype == NULL
+		&& lp->ll_tv == &v->di_tv
+		&& ht != NULL && ht == get_script_local_ht())
+	{
+	    svar_T  *sv = find_typval_in_script(lp->ll_tv);
+
+	    // Vim9 script local variable: get the type
+	    if (sv != NULL)
+		lp->ll_valtype = sv->sv_type;
+	}
+
 	len = -1;
 	if (*p == '.')
 	{
@@ -1037,6 +1048,10 @@ get_lval(
 		}
 	    }
 
+	    if (lp->ll_valtype != NULL)
+		// use the type of the member
+		lp->ll_valtype = lp->ll_valtype->tt_member;
+
 	    if (lp->ll_di == NULL)
 	    {
 		// Can't add "v:" or "a:" variable.
@@ -1148,6 +1163,10 @@ get_lval(
 		return NULL;
 	    }
 
+	    if (lp->ll_valtype != NULL)
+		// use the type of the member
+		lp->ll_valtype = lp->ll_valtype->tt_member;
+
 	    /*
 	     * May need to find the item or absolute index for the second
 	     * index of a range.
@@ -1383,6 +1402,11 @@ set_var_lval(
 	    emsg(_("E996: Cannot lock a list or dict"));
 	    return;
 	}
+
+	if (lp->ll_valtype != NULL
+			&& check_typval_type(lp->ll_valtype, rettv, 0) == FAIL)
+	    return;
+
 	if (lp->ll_newkey != NULL)
 	{
 	    if (op != NULL && *op != '=')