Patch 8.2.3717
Problem:    Vim9: error for constant list size is only given at runtime.
Solution:   Give the error at compile time if possible.
Files:      src/vim9compile.c, src/testdir/test_vim9_assign.vim,
            src/testdir/test_vim9_script.vim,
            src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.3716/src/vim9compile.c   2021-12-01 15:22:53.106902067 +0000
--- src/vim9compile.c   2021-12-01 17:28:00.632285999 +0000
***************
*** 6999,7004 ****
--- 6999,7006 ----
        if (cctx->ctx_skip != SKIP_YES)
        {
            type_T      *stacktype;
+           int         needed_list_len;
+           int         did_check = FALSE;
  
            stacktype = stack->ga_len == 0 ? &t_void
                              : ((type_T **)stack->ga_data)[stack->ga_len - 1];
***************
*** 7010,7018 ****
            if (need_type(stacktype, &t_list_any, -1, 0, cctx,
                                                         FALSE, FALSE) == FAIL)
                goto theend;
!           // TODO: check the length of a constant list here
!           generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count,
!                                                                   semicolon);
            if (stacktype->tt_member != NULL)
                rhs_type = stacktype->tt_member;
        }
--- 7012,7037 ----
            if (need_type(stacktype, &t_list_any, -1, 0, cctx,
                                                         FALSE, FALSE) == FAIL)
                goto theend;
!           // If a constant list was used we can check the length right here.
!           needed_list_len = semicolon ? var_count - 1 : var_count;
!           if (instr->ga_len > 0)
!           {
!               isn_T   *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
! 
!               if (isn->isn_type == ISN_NEWLIST)
!               {
!                   did_check = TRUE;
!                   if (semicolon ? isn->isn_arg.number < needed_list_len
!                           : isn->isn_arg.number != needed_list_len)
!                   {
!                       semsg(_(e_expected_nr_items_but_got_nr),
!                                        needed_list_len, isn->isn_arg.number);
!                       goto theend;
!                   }
!               }
!           }
!           if (!did_check)
!               generate_CHECKLEN(cctx, needed_list_len, semicolon);
            if (stacktype->tt_member != NULL)
                rhs_type = stacktype->tt_member;
        }
*** ../vim-8.2.3716/src/testdir/test_vim9_assign.vim    2021-11-30 
16:14:44.056582159 +0000
--- src/testdir/test_vim9_assign.vim    2021-12-01 17:30:41.646989076 +0000
***************
*** 386,391 ****
--- 386,412 ----
    lines =<< trim END
        var v1: number
        var v2: number
+       [v1, v2] = [1, 2, 3]
+   END
+   CheckDefFailure(lines, 'E1093: Expected 2 items but got 3', 3)
+ 
+   lines =<< trim END
+       var v1: number
+       var v2: number
+       [v1, v2] = [1]
+   END
+   CheckDefFailure(lines, 'E1093: Expected 2 items but got 1', 3)
+ 
+   lines =<< trim END
+       var v1: number
+       var v2: number
+       [v1, v2; _] = [1]
+   END
+   CheckDefFailure(lines, 'E1093: Expected 2 items but got 1', 3)
+ 
+   lines =<< trim END
+       var v1: number
+       var v2: number
        [v1, v2] = 
    END
    CheckDefFailure(lines, 'E1097:', 5)
*** ../vim-8.2.3716/src/testdir/test_vim9_script.vim    2021-11-22 
20:10:14.886598758 +0000
--- src/testdir/test_vim9_script.vim    2021-12-01 17:34:57.069460371 +0000
***************
*** 496,503 ****
    endtry
    assert_equal(266, n)
  
    try
!     [n] = [1, 2, 3]
    catch /E1093:/
      n = 277
    endtry
--- 496,504 ----
    endtry
    assert_equal(266, n)
  
+   l = [1, 2, 3] 
    try
!     [n] = l
    catch /E1093:/
      n = 277
    endtry
***************
*** 4327,4333 ****
          var x: string
          var y: string
          # this error should be caught with CHECKLEN
!         [x, y] = ['']
        catch
          g:caught = 'yes'
        endtry
--- 4328,4335 ----
          var x: string
          var y: string
          # this error should be caught with CHECKLEN
!         var sl = ['']
!         [x, y] = sl
        catch
          g:caught = 'yes'
        endtry
*** ../vim-8.2.3716/src/testdir/test_vim9_disassemble.vim       2021-12-01 
15:22:53.106902067 +0000
--- src/testdir/test_vim9_disassemble.vim       2021-12-01 17:37:00.896883090 
+0000
***************
*** 471,477 ****
          '\d\+ PUSHNR 4\_s*' ..
          '\d\+ PUSHNR 5\_s*' ..
          '\d\+ NEWLIST size 2\_s*' ..
-         '\d\+ CHECKLEN 2\_s*' ..
          '\d\+ LOAD $0\_s*' ..
          '\d\+ ITEM 0 with op\_s*' ..
          '\d\+ OPNR +\_s*' ..
--- 471,476 ----
*** ../vim-8.2.3716/src/version.c       2021-12-01 15:22:53.110902056 +0000
--- src/version.c       2021-12-01 17:31:07.874805860 +0000
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     3717,
  /**/

-- 
Hanson's Treatment of Time:
        There are never enough hours in a day, but always too
        many days before Saturday.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211201173922.0F9B11C025D%40moolenaar.net.

Raspunde prin e-mail lui