patch 9.1.0398: Vim9: imported vars are not properly type checked

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>
diff --git a/src/eval.c b/src/eval.c
index a91ca2d..b547143 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1170,12 +1170,10 @@
     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 @@
 								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 @@
 	goto failed;
 
     lp->ll_tv = &di->di_tv;
+    lp->ll_valtype = type;
 
 success:
     rc = OK;
@@ -1410,8 +1399,7 @@
 	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 @@
 								       == 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 @@
 		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 @@
 	}
     }
 
+    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;