summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2024-05-08 20:24:33 +0200
committerChristian Brabandt <cb@256bit.org>2024-05-08 20:24:33 +0200
commit9937d8b61922a02311509fb3352583d9e8c54885 (patch)
treebbd19a2854e11b36e3ed535872e82fbe4d24352b /src/eval.c
parentc7a8eb5ff2ddd919e6f39faec93d81c52874695a (diff)
patch 9.1.0398: Vim9: imported vars are not properly type checkedv9.1.0398
Problem: Vim9: imported vars are not properly type checked Solution: Check the imported variable type properly (Yegappan Lakshmanan) closes: #14729 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/eval.c b/src/eval.c
index a91ca2d3e5..b547143fe3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1170,12 +1170,10 @@ get_lval_check_access(
static char_u *
get_lval_imported(
lval_T *lp,
- typval_T *rettv,
scid_T imp_sid,
char_u *p,
dictitem_T **dip,
- int fne_flags,
- int vim9script)
+ int fne_flags)
{
ufunc_T *ufunc;
type_T *type = NULL;
@@ -1197,16 +1195,6 @@ get_lval_imported(
TRUE) == -1)
goto failed;
- if (vim9script && type != NULL)
- {
- where_T where = WHERE_INIT;
-
- // In a vim9 script, do type check and make sure the variable is
- // writable.
- if (check_typval_type(type, rettv, where) == FAIL)
- goto failed;
- }
-
// Get the typval for the exported item
hashtab_T *ht = &SCRIPT_VARS(imp_sid);
if (ht == NULL)
@@ -1232,6 +1220,7 @@ get_lval_imported(
goto failed;
lp->ll_tv = &di->di_tv;
+ lp->ll_valtype = type;
success:
rc = OK;
@@ -1410,8 +1399,7 @@ get_lval(
if (import != NULL)
{
p++; // skip '.'
- p = get_lval_imported(lp, rettv, import->imp_sid, p, &v,
- fne_flags, vim9script);
+ p = get_lval_imported(lp, import->imp_sid, p, &v, fne_flags);
if (p == NULL)
return NULL;
}
@@ -1754,6 +1742,12 @@ get_lval(
== FAIL)
return NULL;
}
+
+ if (!lp->ll_range)
+ // Indexing a single byte in a blob. So the rhs type is a
+ // number.
+ lp->ll_valtype = &t_number;
+
lp->ll_blob = lp->ll_tv->vval.v_blob;
lp->ll_tv = NULL;
break;
@@ -1782,7 +1776,7 @@ get_lval(
return NULL;
}
- if (lp->ll_valtype != NULL)
+ if (lp->ll_valtype != NULL && !lp->ll_range)
// use the type of the member
lp->ll_valtype = lp->ll_valtype->tt_member;
@@ -1896,6 +1890,17 @@ get_lval(
}
}
+ if (vim9script && lp->ll_valtype != NULL && rettv != NULL)
+ {
+ where_T where = WHERE_INIT;
+
+ // In a vim9 script, do type check and make sure the variable is
+ // writable.
+ if (check_typval_type(lp->ll_valtype, rettv, where) == FAIL)
+ return NULL;
+ }
+
+
clear_tv(&var1);
lp->ll_name_end = p;
return p;