patch 8.2.1011: Vim9: some code not tested

Problem:    Vim9: some code not tested.
Solution:   Add a few more test cases.  Reorder checks for clearer error.
            Remove unreachable code.
diff --git a/src/evalvars.c b/src/evalvars.c
index 0a0bbc4..fa52e96 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2886,10 +2886,6 @@
 		return;
 	    }
 
-	    if (var_check_ro(di->di_flags, name, FALSE)
-			       || var_check_lock(di->di_tv.v_lock, name, FALSE))
-		return;
-
 	    if (is_script_local
 			     && current_sctx.sc_version == SCRIPT_VERSION_VIM9)
 	    {
@@ -2900,8 +2896,13 @@
 		}
 
 		// check the type
-		check_script_var_type(&di->di_tv, tv, name);
+		if (check_script_var_type(&di->di_tv, tv, name) == FAIL)
+		    return;
 	    }
+
+	    if (var_check_ro(di->di_flags, name, FALSE)
+			       || var_check_lock(di->di_tv.v_lock, name, FALSE))
+		return;
 	}
 	else
 	    // can only redefine once
diff --git a/src/proto/vim9script.pro b/src/proto/vim9script.pro
index 3a7b6e1..a11f6af 100644
--- a/src/proto/vim9script.pro
+++ b/src/proto/vim9script.pro
@@ -7,5 +7,5 @@
 int find_exported(int sid, char_u **argp, int *name_len, ufunc_T **ufunc, type_T **type);
 char_u *handle_import(char_u *arg_start, garray_T *gap, int import_sid, void *cctx);
 char_u *vim9_declare_scriptvar(exarg_T *eap, char_u *arg);
-void check_script_var_type(typval_T *dest, typval_T *value, char_u *name);
+int check_script_var_type(typval_T *dest, typval_T *value, char_u *name);
 /* vim: set ft=c : */
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index e0776b5..224f4fd 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -524,6 +524,7 @@
 			g:anint)
   assert_equal(9, g:alsoint + 5)
   assert_equal(14, g:alsoint + g:anint)
+  assert_equal([1, 2, 3, 4], [1] + g:alist)
 
   assert_equal(54, 60 - 6)
   assert_equal(50, 60 -
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 25fed4a..3cfacbb 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -140,6 +140,9 @@
   let dict4: dict<any> = #{one: 1, two: '2'}
   let dict5: dict<blob> = #{one: 0z01, two: 0z02}
 
+  " overwrite
+  dict3['key'] = 'another'
+
   call CheckDefExecFailure(['let dd = {}', 'dd[""] = 6'], 'E713:')
 
   # type becomes dict<any>
@@ -219,6 +222,13 @@
 
     let thechannel: channel
     assert_equal(test_null_channel(), thechannel)
+
+    if has('unix') && executable('cat')
+      " check with non-null job and channel, types must match
+      thejob = job_start("cat ", #{})
+      thechannel = job_getchannel(thejob)
+      job_stop(thejob, 'kill')
+    endif
   endif
 
   let nr = 1234 | nr = 5678
@@ -775,6 +785,9 @@
   CheckScriptFailure(['vim9script', 'export let g:some'], 'E1044:')
   CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
 
+  CheckScriptFailure(['vim9script', 'let str: string', 'str = 1234'], 'E1013:')
+  CheckScriptFailure(['vim9script', 'const str = "asdf"', 'str = "xxx"'], 'E46:')
+
   assert_fails('vim9script', 'E1038')
   assert_fails('export something', 'E1043')
 enddef
diff --git a/src/version.c b/src/version.c
index f1e274a..cc580fb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1011,
+/**/
     1010,
 /**/
     1009,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 53a30c9..4271f38 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2144,18 +2144,10 @@
 		    listitem_T	*li;
 		    int		index = iptr->isn_arg.number;
 
-		    // get list item: list is at stack-1, push item
+		    // Get list item: list is at stack-1, push item.
+		    // List type and length is checked for when compiling.
 		    tv = STACK_TV_BOT(-1);
-		    if (tv->v_type != VAR_LIST)
-		    {
-			emsg(_(e_listreq));
-			goto failed;
-		    }
-		    if ((li = list_find(tv->vval.v_list, index)) == NULL)
-		    {
-			semsg(_(e_listidx), index);
-			goto failed;
-		    }
+		    li = list_find(tv->vval.v_list, index);
 
 		    if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
 			goto failed;
diff --git a/src/vim9script.c b/src/vim9script.c
index 442158c..6c4cbc4 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -507,7 +507,7 @@
 /*
  * Check if the type of script variable "dest" allows assigning "value".
  */
-    void
+    int
 check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
 {
     scriptitem_T    *si = SCRIPT_ITEM(current_sctx.sc_sid);
@@ -521,13 +521,15 @@
 	if (sv->sv_tv == dest)
 	{
 	    if (sv->sv_const)
+	    {
 		semsg(_(e_readonlyvar), name);
-	    else
-		check_type(sv->sv_type, typval2type(value), TRUE);
-	    return;
+		return FAIL;
+	    }
+	    return check_type(sv->sv_type, typval2type(value), TRUE);
 	}
     }
     iemsg("check_script_var_type(): not found");
+    return OK; // not really
 }
 
 #endif // FEAT_EVAL