Patch 8.2.3015
Problem:    Vim9: Assigning to @# requires a string. (Naohiro Ono)
Solution:   Accent a number or a string. (closes #8396)
Files:      src/vim9compile.c, src/vim9execute.c, src/globals.h,
            src/testdir/test_vim9_assign.vim


*** ../vim-8.2.3014/src/vim9compile.c   2021-06-16 19:19:44.870445048 +0200
--- src/vim9compile.c   2021-06-17 21:01:50.394822736 +0200
***************
*** 5852,5858 ****
            return FAIL;
        }
        *dest = dest_reg;
!       *type = &t_string;
      }
      else if (STRNCMP(name, "g:", 2) == 0)
      {
--- 5852,5858 ----
            return FAIL;
        }
        *dest = dest_reg;
!       *type = name[1] == '#' ? &t_number_or_string : &t_string;
      }
      else if (STRNCMP(name, "g:", 2) == 0)
      {
***************
*** 5927,5933 ****
        case dest_env:
            return generate_STORE(cctx, ISN_STOREENV, 0, name + 1);
        case dest_reg:
!           return generate_STORE(cctx, ISN_STOREREG, name[1], NULL);
        case dest_vimvar:
            return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
        case dest_script:
--- 5927,5934 ----
        case dest_env:
            return generate_STORE(cctx, ISN_STOREENV, 0, name + 1);
        case dest_reg:
!           return generate_STORE(cctx, ISN_STOREREG,
!                                        name[1] == '@' ? '"' : name[1], NULL);
        case dest_vimvar:
            return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
        case dest_script:
***************
*** 6843,6851 ****
                            goto theend;
                    }
                }
!               else if (*p != '=' && need_type(rhs_type, lhs.lhs_member_type,
                                            -1, 0, cctx, FALSE, FALSE) == FAIL)
                    goto theend;
            }
            else if (cmdidx == CMD_final)
            {
--- 6844,6862 ----
                            goto theend;
                    }
                }
!               else
!               {
!                   type_T *lhs_type = lhs.lhs_member_type;
! 
!                   // Special case: assigning to @# can use a number or a
!                   // string.
!                   if (lhs_type == &t_number_or_string
!                                           && rhs_type->tt_type == VAR_NUMBER)
!                       lhs_type = &t_number;
!                   if (*p != '=' && need_type(rhs_type, lhs_type,
                                            -1, 0, cctx, FALSE, FALSE) == FAIL)
                    goto theend;
+               }
            }
            else if (cmdidx == CMD_final)
            {
*** ../vim-8.2.3014/src/vim9execute.c   2021-06-17 13:53:37.491513177 +0200
--- src/vim9execute.c   2021-06-17 20:36:33.341445459 +0200
***************
*** 2182,2189 ****
  
                    --ectx->ec_stack.ga_len;
                    tv = STACK_TV_BOT(0);
!                   write_reg_contents(reg == '@' ? '"' : reg,
!                                                tv_get_string(tv), -1, FALSE);
                    clear_tv(tv);
                }
                break;
--- 2182,2188 ----
  
                    --ectx->ec_stack.ga_len;
                    tv = STACK_TV_BOT(0);
!                   write_reg_contents(reg, tv_get_string(tv), -1, FALSE);
                    clear_tv(tv);
                }
                break;
*** ../vim-8.2.3014/src/globals.h       2021-05-18 15:32:07.857673075 +0200
--- src/globals.h       2021-06-17 20:46:19.296602461 +0200
***************
*** 418,423 ****
--- 418,426 ----
  EXTERN type_T t_job INIT6(VAR_JOB, 0, 0, TTFLAG_STATIC, NULL, NULL);
  EXTERN type_T t_channel INIT6(VAR_CHANNEL, 0, 0, TTFLAG_STATIC, NULL, NULL);
  
+ // Special value used for @#.
+ EXTERN type_T t_number_or_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, 
NULL);
+ 
  EXTERN type_T t_func_unknown INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, 
&t_unknown, NULL);
  EXTERN type_T t_func_void INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_void, 
NULL);
  EXTERN type_T t_func_any INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_any, NULL);
*** ../vim-8.2.3014/src/testdir/test_vim9_assign.vim    2021-06-12 
14:52:35.953230564 +0200
--- src/testdir/test_vim9_assign.vim    2021-06-17 21:00:20.975045908 +0200
***************
*** 1820,1825 ****
--- 1820,1838 ----
    CheckDefAndScriptSuccess(lines)
  enddef
  
+ def Test_assign_alt_buf_register()
+   var lines =<< trim END
+       edit 'file_b1'
+       var b1 = bufnr()
+       edit 'file_b2'
+       var b2 = bufnr()
+       assert_equal(b1, bufnr('#'))
+       @# = b2
+       assert_equal(b2, bufnr('#'))
+   END
+   CheckDefAndScriptSuccess(lines)
+ enddef
+ 
  def Test_script_funcref_case()
    var lines =<< trim END
        var Len = (s: string): number => len(s) + 1
*** ../vim-8.2.3014/src/version.c       2021-06-17 13:53:37.491513177 +0200
--- src/version.c       2021-06-17 20:46:37.700587115 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     3015,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
5. You find yourself brainstorming for new subjects to search.

 /// 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/202106171903.15HJ3vsc1717769%40masaka.moolenaar.net.

Raspunde prin e-mail lui