]> granicus.if.org Git - vim/commitdiff
patch 8.2.4582: useless code handling a type declaration v8.2.4582
authorBram Moolenaar <Bram@vim.org>
Wed, 16 Mar 2022 20:01:39 +0000 (20:01 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 16 Mar 2022 20:01:39 +0000 (20:01 +0000)
Problem:    Useless code handling a type declaration.
Solution:   Remove the code and give an error.

src/errors.h
src/eval.c
src/testdir/dumps/Test_misplaced_type.dump [new file with mode: 0644]
src/testdir/test_vim9_script.vim
src/version.c

index b8e94197944e40b5a81217151011912e8e6b461e..7bc4b1d49f09e5b4f87301523801fb3339973ab6 100644 (file)
@@ -3252,4 +3252,6 @@ EXTERN char e_cannot_use_s_backslash_in_vim9_script[]
 #ifdef FEAT_EVAL
 EXTERN char e_compiling_closure_without_context_str[]
        INIT(= N_("E1271: compiling closure without context: %s"));
+EXTERN char e_using_type_not_in_script_context_str[]
+       INIT(= N_("E1272: Using type not in a script context: %s"));
 #endif
index 62266f884b2a4f6fa3ff6b029a90d902f85f1fec..e4f47b18bd345990772c3ee8a49a0846dd3f227e 100644 (file)
@@ -937,8 +937,6 @@ get_lval(
            }
            if (*p == ':')
            {
-               garray_T    tmp_type_list;
-               garray_T    *type_list;
                char_u      *tp = skipwhite(p + 1);
 
                if (tp == p + 1 && !quiet)
@@ -947,27 +945,19 @@ get_lval(
                    return NULL;
                }
 
-               if (SCRIPT_ID_VALID(current_sctx.sc_sid))
-                   type_list = &SCRIPT_ITEM(current_sctx.sc_sid)->sn_type_list;
-               else
+               if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
                {
-                   // TODO: should we give an error here?
-                   type_list = &tmp_type_list;
-                   ga_init2(type_list, sizeof(type_T), 10);
+                   semsg(_(e_using_type_not_in_script_context_str), p);
+                   return NULL;
                }
 
                // parse the type after the name
-               lp->ll_type = parse_type(&tp, type_list, !quiet);
+               lp->ll_type = parse_type(&tp,
+                              &SCRIPT_ITEM(current_sctx.sc_sid)->sn_type_list,
+                              !quiet);
                if (lp->ll_type == NULL && !quiet)
                    return NULL;
                lp->ll_name_end = tp;
-
-               // drop the type when not in a script
-               if (type_list == &tmp_type_list)
-               {
-                   lp->ll_type = NULL;
-                   clear_type_list(type_list);
-               }
            }
        }
     }
diff --git a/src/testdir/dumps/Test_misplaced_type.dump b/src/testdir/dumps/Test_misplaced_type.dump
new file mode 100644 (file)
index 0000000..afb82a0
--- /dev/null
@@ -0,0 +1,6 @@
+|~+0#4040ff13#ffffff0| @73
+|~| @73
+|~| @73
+|~| @73
+|E+0#ffffff16#e000002|1|2|7|2|:| |U|s|i|n|g| |t|y|p|e| |n|o|t| |i|n| |a| |s|c|r|i|p|t| |c|o|n|t|e|x|t|:| |:| |s|t|r|i|n|g| +0#0000000#ffffff0@23
+|P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| |c|o|n|t|i|n|u|e> +0#0000000&@35
index ec0d54797f585f3d687c59384b79988028bedf18..3ad9c9d4f55c664b5562e84ae02d8b239b2dc8fc 100644 (file)
@@ -3942,10 +3942,6 @@ def Test_profile_with_lambda()
       enddef
 
       def Profile()
-        profile start Xprofile.log
-        profile func ProfiledWithLambda
-        # mark ProfiledNested for profiling to avoid E1271
-        profile func ProfiledNested
         ProfiledWithLambda()
         ProfiledNested()
 
@@ -3957,8 +3953,20 @@ def Test_profile_with_lambda()
         profdel func *
         profile pause
       enddef
-      Profile()
-      writefile(['done'], 'Xdidprofile')
+
+      var result = 'done'
+      try
+        # mark functions for profiling now to avoid E1271
+        profile start Xprofile.log
+        profile func ProfiledWithLambda
+        profile func ProfiledNested
+
+        Profile()
+      catch
+        result = 'failed: ' .. v:exception
+      finally
+        writefile([result], 'Xdidprofile')
+      endtry
   END
   writefile(lines, 'Xprofile.vim')
   call system(g:GetVimCommand()
@@ -3974,6 +3982,16 @@ def Test_profile_with_lambda()
   delete('Xprofile.vim')
 enddef
 
+def Test_misplaced_type()
+  writefile(['let g:somevar = "asdf"'], 'XTest_misplaced_type')
+  var buf = g:RunVimInTerminal('-S XTest_misplaced_type', {'rows': 6})
+  term_sendkeys(buf, ":vim9cmd echo islocked('g:somevar: string')\<CR>")
+  g:VerifyScreenDump(buf, 'Test_misplaced_type', {})
+
+  g:StopVimInTerminal(buf)
+  delete('XTest_misplaced_type')
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
index fd632792269075e3baee4b1ef9f1f7303756b968..e3873d5e947ab20bb12830e6f2cb4838915acf91 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4582,
 /**/
     4581,
 /**/