Patch 8.2.2339
Problem:    Cannot get the type of a value as a string.
Solution:   Add typename().
Files:      runtime/doc/eval.txt, runtime/doc/usr_41.txt, src/evalfunc.c,
            src/vim9type.c, src/proto/vim9type.pro,
            src/testdir/test_vimscript.vim, src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.2338/runtime/doc/eval.txt        2021-01-12 20:23:35.774707897 
+0100
--- runtime/doc/eval.txt        2021-01-12 21:27:54.094638053 +0100
***************
*** 2980,2986 ****
  trim({text} [, {mask} [, {dir}]])
                                String  trim characters in {mask} from {text}
  trunc({expr})                 Float   truncate Float {expr}
! type({name})                  Number  type of variable {name}
  undofile({name})              String  undo file name for {name}
  undotree()                    List    undo file tree
  uniq({list} [, {func} [, {dict}]])
--- 3016,3023 ----
  trim({text} [, {mask} [, {dir}]])
                                String  trim characters in {mask} from {text}
  trunc({expr})                 Float   truncate Float {expr}
! type({expr})                  Number  type of value {expr}
! typename({expr})              String  representation of the type of {expr}
  undofile({name})              String  undo file name for {name}
  undotree()                    List    undo file tree
  uniq({list} [, {func} [, {dict}]])
***************
*** 11034,11039 ****
--- 11130,11143 ----
  <             Can also be used as a |method|: >
                        mylist->type()
  
+ 
+ typename({expr})                                      *typename()*
+               Return a string representation of the type of {expr}.
+               Example: >
+                       echo typename([1, 2, 3])
+                       list<number>
+ 
+ 
  undofile({name})                                      *undofile()*
                Return the name of the undo file that would be used for a file
                with name {name} when writing.  This uses the 'undodir'
*** ../vim-8.2.2338/runtime/doc/usr_41.txt      2021-01-12 20:23:35.778707890 
+0100
--- runtime/doc/usr_41.txt      2021-01-12 21:28:17.906568811 +0100
***************
*** 712,718 ****
        srand()                 initialize seed used by rand()
  
  Variables:                                            *var-functions*
!       type()                  type of a variable
        islocked()              check if a variable is locked
        funcref()               get a Funcref for a function reference
        function()              get a Funcref for a function name
--- 720,727 ----
        srand()                 initialize seed used by rand()
  
  Variables:                                            *var-functions*
!       type()                  type of a variable as a number
!       typename()              type of a variable as text
        islocked()              check if a variable is locked
        funcref()               get a Funcref for a function reference
        function()              get a Funcref for a function name
*** ../vim-8.2.2338/src/evalfunc.c      2021-01-12 21:22:27.667588992 +0100
--- src/evalfunc.c      2021-01-12 21:25:12.431108329 +0100
***************
*** 1742,1747 ****
--- 1742,1749 ----
                        ret_float,          FLOAT_FUNC(f_trunc)},
      {"type",          1, 1, FEARG_1,      NULL,
                        ret_number,         f_type},
+     {"typename",      1, 1, FEARG_1,      NULL,
+                       ret_string,         f_typename},
      {"undofile",      1, 1, FEARG_1,      NULL,
                        ret_string,         f_undofile},
      {"undotree",      0, 0, 0,            NULL,
*** ../vim-8.2.2338/src/vim9type.c      2021-01-06 21:59:35.174021934 +0100
--- src/vim9type.c      2021-01-12 21:36:23.749160412 +0100
***************
*** 1170,1173 ****
--- 1170,1198 ----
      return name;
  }
  
+ /*
+  * "typename(expr)" function
+  */
+     void
+ f_typename(typval_T *argvars, typval_T *rettv)
+ {
+     garray_T  type_list;
+     type_T    *type;
+     char      *tofree;
+     char      *name;
+ 
+     rettv->v_type = VAR_STRING;
+     ga_init2(&type_list, sizeof(type_T *), 10);
+     type = typval2type(argvars, &type_list);
+     name = type_name(type, &tofree);
+     if (tofree != NULL)
+       rettv->vval.v_string = (char_u *)tofree;
+     else
+     {
+       rettv->vval.v_string = vim_strsave((char_u *)name);
+       vim_free(tofree);
+     }
+     clear_type_list(&type_list);
+ }
+ 
  #endif // FEAT_EVAL
*** ../vim-8.2.2338/src/proto/vim9type.pro      2021-01-06 21:59:35.174021934 
+0100
--- src/proto/vim9type.pro      2021-01-12 21:34:44.733447045 +0100
***************
*** 24,27 ****
--- 24,28 ----
  type_T *get_member_type_from_stack(type_T **stack_top, int count, int skip, 
garray_T *type_gap);
  char *vartype_name(vartype_T type);
  char *type_name(type_T *type, char **tofree);
+ void f_typename(typval_T *argvars, typval_T *rettv);
  /* vim: set ft=c : */
*** ../vim-8.2.2338/src/testdir/test_vimscript.vim      2020-12-18 
19:49:52.349571840 +0100
--- src/testdir/test_vimscript.vim      2021-01-12 21:41:00.980358724 +0100
***************
*** 6600,6605 ****
--- 6600,6613 ----
      call ChangeYourMind()
  endfunc
  
+ func Test_typename()
+   call assert_equal('number', typename(123))
+   call assert_equal('string', typename('x'))
+   call assert_equal('list<number>', typename([123]))
+   call assert_equal('dict<number>', typename(#{key: 123}))
+   call assert_equal('list<dict<number>>', typename([#{key: 123}]))
+ endfunc
+ 
  
"-------------------------------------------------------------------------------
  " Test 92:  skipping code                                         {{{1
  
"-------------------------------------------------------------------------------
*** ../vim-8.2.2338/src/testdir/test_vim9_builtin.vim   2021-01-12 
21:22:27.667588992 +0100
--- src/testdir/test_vim9_builtin.vim   2021-01-12 21:47:05.971415855 +0100
***************
*** 318,325 ****
    if has('job')
      job_start(&shell)
      var jobs = job_info()
!     assert_equal(v:t_list, type(jobs))
!     assert_equal(v:t_dict, type(job_info(jobs[0])))
      job_stop(jobs[0])
    endif
  enddef
--- 318,325 ----
    if has('job')
      job_start(&shell)
      var jobs = job_info()
!     assert_equal('list<job>', typename(jobs))
!     assert_equal('dict<any>', typename(job_info(jobs[0])))
      job_stop(jobs[0])
    endif
  enddef
*** ../vim-8.2.2338/src/version.c       2021-01-12 21:22:27.667588992 +0100
--- src/version.c       2021-01-12 21:40:00.392533875 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2339,
  /**/

-- 
Never eat yellow snow.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202101122049.10CKnQXx1087206%40masaka.moolenaar.net.

Raspunde prin e-mail lui