Patch 8.2.4455
Problem:    Accepting one and zero for the second sort() argument is strange.
Solution:   Disallow using one and zero in Vim9 script.
Files:      runtime/doc/builtin.txt, src/evalfunc.c, src/list.c,
            src/testdir/test_listdict.vim


*** ../vim-8.2.4454/runtime/doc/builtin.txt     2022-01-31 17:39:45.390105589 
+0000
--- runtime/doc/builtin.txt     2022-02-23 12:48:44.883042477 +0000
***************
*** 539,546 ****
  sinh({expr})                  Float   hyperbolic sine of {expr}
  slice({expr}, {start} [, {end}])  String, List or Blob
                                        slice of a String, List or Blob
! sort({list} [, {func} [, {dict}]])
!                               List    sort {list}, using {func} to compare
  sound_clear()                 none    stop playing all sounds
  sound_playevent({name} [, {callback}])
                                Number  play an event sound
--- 539,546 ----
  sinh({expr})                  Float   hyperbolic sine of {expr}
  slice({expr}, {start} [, {end}])  String, List or Blob
                                        slice of a String, List or Blob
! sort({list} [, {how} [, {dict}]])
!                               List    sort {list}, compare with {how}
  sound_clear()                 none    stop playing all sounds
  sound_playevent({name} [, {callback}])
                                Number  play an event sound
***************
*** 8006,8026 ****
                        GetList()->slice(offset)
  
  
! sort({list} [, {func} [, {dict}]])                    *sort()* *E702*
                Sort the items in {list} in-place.  Returns {list}.
  
                If you want a list to remain unmodified make a copy first: >
                        :let sortedlist = sort(copy(mylist))
  
! <             When {func} is omitted, is empty or zero, then sort() uses the
                string representation of each item to sort on.  Numbers sort
                after Strings, |Lists| after Numbers.  For sorting text in the
                current buffer use |:sort|.
  
!               When {func} is given and it is '1' or 'i' then case is
!               ignored.
  
!               When {func} is given and it is 'l' then the current collation
                locale is used for ordering. Implementation details: strcoll()
                is used to compare strings. See |:language| check or set the
                collation locale. |v:collate| can also be used to check the
--- 8033,8054 ----
                        GetList()->slice(offset)
  
  
! sort({list} [, {how} [, {dict}]])                     *sort()* *E702*
                Sort the items in {list} in-place.  Returns {list}.
  
                If you want a list to remain unmodified make a copy first: >
                        :let sortedlist = sort(copy(mylist))
  
! <             When {how} is omitted or is an string, then sort() uses the
                string representation of each item to sort on.  Numbers sort
                after Strings, |Lists| after Numbers.  For sorting text in the
                current buffer use |:sort|.
  
!               When {how} is given and it is 'i' then case is ignored.
!               In legacy script, for backwards compatibility, the value one
!               can be used to ignore case.  Zero means to not ignore case.
  
!               When {how} is given and it is 'l' then the current collation
                locale is used for ordering. Implementation details: strcoll()
                is used to compare strings. See |:language| check or set the
                collation locale. |v:collate| can also be used to check the
***************
*** 8037,8055 ****
  <                     ['n', 'o', 'O', 'p', 'z', 'ö'] ~
                This does not work properly on Mac.
  
!               When {func} is given and it is 'n' then all items will be
                sorted numerical (Implementation detail: this uses the
                strtod() function to parse numbers, Strings, Lists, Dicts and
                Funcrefs will be considered as being 0).
  
!               When {func} is given and it is 'N' then all items will be
                sorted numerical. This is like 'n' but a string containing
                digits will be used as the number they represent.
  
!               When {func} is given and it is 'f' then all items will be
                sorted numerical. All values must be a Number or a Float.
  
!               When {func} is a |Funcref| or a function name, this function
                is called to compare items.  The function is invoked with two
                items as argument and must return zero if they are equal, 1 or
                bigger if the first one sorts after the second one, -1 or
--- 8065,8083 ----
  <                     ['n', 'o', 'O', 'p', 'z', 'ö'] ~
                This does not work properly on Mac.
  
!               When {how} is given and it is 'n' then all items will be
                sorted numerical (Implementation detail: this uses the
                strtod() function to parse numbers, Strings, Lists, Dicts and
                Funcrefs will be considered as being 0).
  
!               When {how} is given and it is 'N' then all items will be
                sorted numerical. This is like 'n' but a string containing
                digits will be used as the number they represent.
  
!               When {how} is given and it is 'f' then all items will be
                sorted numerical. All values must be a Number or a Float.
  
!               When {how} is a |Funcref| or a function name, this function
                is called to compare items.  The function is invoked with two
                items as argument and must return zero if they are equal, 1 or
                bigger if the first one sorts after the second one, -1 or
*** ../vim-8.2.4454/src/evalfunc.c      2022-02-22 22:53:06.872652538 +0000
--- src/evalfunc.c      2022-02-23 12:50:46.486426803 +0000
***************
*** 603,609 ****
  {
      if (type->tt_type == VAR_STRING
            || type->tt_type == VAR_PARTIAL
-           || type->tt_type == VAR_NUMBER  // 1 means ignore case
            || type == &t_unknown
            || type == &t_any)
        return OK;
--- 603,608 ----
*** ../vim-8.2.4454/src/list.c  2022-02-04 11:36:47.414816959 +0000
--- src/list.c  2022-02-23 12:57:19.352645849 +0000
***************
*** 2198,2204 ****
      if (in_vim9script()
            && (check_for_list_arg(argvars, 0) == FAIL
                || (argvars[1].v_type != VAR_UNKNOWN
!                   && check_for_opt_dict_arg(argvars, 2) == FAIL)))
        return;
  
      if (argvars[0].v_type != VAR_LIST)
--- 2198,2205 ----
      if (in_vim9script()
            && (check_for_list_arg(argvars, 0) == FAIL
                || (argvars[1].v_type != VAR_UNKNOWN
!                   && (check_for_string_or_func_arg(argvars, 1) == FAIL
!                             || check_for_opt_dict_arg(argvars, 2) == FAIL))))
        return;
  
      if (argvars[0].v_type != VAR_LIST)
*** ../vim-8.2.4454/src/testdir/test_listdict.vim       2022-02-22 
22:53:06.872652538 +0000
--- src/testdir/test_listdict.vim       2022-02-23 12:57:53.024523970 +0000
***************
*** 949,955 ****
          call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 
7, 9, 12, 18, 22, 255], sort(copy(l), 'n'))
  
          LET l = [7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 
'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
!         call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 
'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], 
sort(copy(l), 1))
          call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 
'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], 
sort(copy(l), 'i'))
          call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 
'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
        endif
--- 949,955 ----
          call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 
7, 9, 12, 18, 22, 255], sort(copy(l), 'n'))
  
          LET l = [7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 
'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
!         call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 
'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], 
sort(copy(l), 'i'))
          call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 
'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], 
sort(copy(l), 'i'))
          call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 
'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
        endif
***************
*** 961,966 ****
--- 961,976 ----
    call assert_fails("call sort([1, 2], function('min'), 1)", "E715:")
    call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:")
    call assert_fails("call sort([1, 2], function('min'))", "E118:")
+ 
+   let lines =<< trim END
+     call sort(['a', 'b'], 0)
+   END
+   call v9.CheckDefAndScriptFailure(lines, 'E1256: String or function required 
for argument 2')
+ 
+   let lines =<< trim END
+     call sort(['a', 'b'], 1)
+   END
+   call v9.CheckDefAndScriptFailure(lines, 'E1256: String or function required 
for argument 2')
  endfunc
  
  " reduce a list, blob or string
*** ../vim-8.2.4454/src/version.c       2022-02-23 12:23:04.501304722 +0000
--- src/version.c       2022-02-23 13:14:26.885864437 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4455,
  /**/

-- 
There's no place like $(HOME)!

 /// 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/20220223131830.AE77D1C0154%40moolenaar.net.

Raspunde prin e-mail lui