Patch 8.2.0346
Problem:    Vim9: finding common list type not tested.
Solution:   Add more tests.  Fix listing function.  Fix overwriting type.
Files:      src/vim9compile.c, src/userfunc.c,
            src/testdir/test_vim9_script.vim, src/testdir/runtest.vim,
            src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.0345/src/vim9compile.c   2020-03-01 17:55:09.005454943 +0100
--- src/vim9compile.c   2020-03-01 23:28:42.360452921 +0100
***************
*** 1443,1449 ****
        case VAR_BLOB:
        case VAR_JOB:
        case VAR_CHANNEL:
!           return TRUE;  // not composite is always OK
        case VAR_LIST:
        case VAR_DICT:
            return equal_type(type1->tt_member, type2->tt_member);
--- 1443,1449 ----
        case VAR_BLOB:
        case VAR_JOB:
        case VAR_CHANNEL:
!           break;  // not composite is always OK
        case VAR_LIST:
        case VAR_DICT:
            return equal_type(type1->tt_member, type2->tt_member);
***************
*** 1461,1487 ****
   * "type2" and "dest" may be the same.
   */
      static void
! common_type(type_T *type1, type_T *type2, type_T *dest)
  {
      if (equal_type(type1, type2))
      {
!       if (dest != type2)
!           *dest = *type2;
        return;
      }
  
      if (type1->tt_type == type2->tt_type)
      {
-       dest->tt_type = type1->tt_type;
        if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
        {
!           common_type(type1->tt_member, type2->tt_member, dest->tt_member);
            return;
        }
        // TODO: VAR_FUNC and VAR_PARTIAL
      }
  
!     dest->tt_type = VAR_UNKNOWN;  // "any"
  }
  
      char *
--- 1461,1492 ----
   * "type2" and "dest" may be the same.
   */
      static void
! common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_list)
  {
      if (equal_type(type1, type2))
      {
!       *dest = type1;
        return;
      }
  
      if (type1->tt_type == type2->tt_type)
      {
        if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
        {
!           type_T *common;
! 
!           common_type(type1->tt_member, type2->tt_member, &common, type_list);
!           if (type1->tt_type == VAR_LIST)
!               *dest = get_list_type(common, type_list);
!           else
!               *dest = get_dict_type(common, type_list);
            return;
        }
        // TODO: VAR_FUNC and VAR_PARTIAL
+       *dest = type1;
      }
  
!     *dest = &t_any;
  }
  
      char *
***************
*** 1501,1507 ****
        case VAR_CHANNEL: return "channel";
        case VAR_LIST: return "list";
        case VAR_DICT: return "dict";
!       case VAR_FUNC: return "function";
        case VAR_PARTIAL: return "partial";
      }
      return "???";
--- 1506,1512 ----
        case VAR_CHANNEL: return "channel";
        case VAR_LIST: return "list";
        case VAR_DICT: return "dict";
!       case VAR_FUNC: return "func";
        case VAR_PARTIAL: return "partial";
      }
      return "???";
***************
*** 3160,3166 ****
  
        // If the types differ, the result has a more generic type.
        type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1];
!       common_type(type1, type2, type2);
  
        // jump here from JUMP_ALWAYS
        isn = ((isn_T *)instr->ga_data) + end_idx;
--- 3165,3171 ----
  
        // If the types differ, the result has a more generic type.
        type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1];
!       common_type(type1, type2, &type2, cctx->ctx_type_list);
  
        // jump here from JUMP_ALWAYS
        isn = ((isn_T *)instr->ga_data) + end_idx;
*** ../vim-8.2.0345/src/userfunc.c      2020-02-19 15:46:45.269950987 +0100
--- src/userfunc.c      2020-03-01 23:10:26.511492137 +0100
***************
*** 1902,1908 ****
  }
  
  /*
!  * List the head of the function: "name(arg1, arg2)".
   */
      static void
  list_func_head(ufunc_T *fp, int indent)
--- 1902,1908 ----
  }
  
  /*
!  * List the head of the function: "function name(arg1, arg2)".
   */
      static void
  list_func_head(ufunc_T *fp, int indent)
***************
*** 1912,1918 ****
      msg_start();
      if (indent)
        msg_puts("   ");
!     msg_puts("function ");
      msg_puts((char *)printable_func_name(fp));
      msg_putchar('(');
      for (j = 0; j < fp->uf_args.ga_len; ++j)
--- 1912,1921 ----
      msg_start();
      if (indent)
        msg_puts("   ");
!     if (fp->uf_dfunc_idx >= 0)
!       msg_puts("def ");
!     else
!       msg_puts("function ");
      msg_puts((char *)printable_func_name(fp));
      msg_putchar('(');
      for (j = 0; j < fp->uf_args.ga_len; ++j)
***************
*** 1957,1963 ****
        }
      }
      msg_putchar(')');
!     if (fp->uf_flags & FC_ABORT)
        msg_puts(" abort");
      if (fp->uf_flags & FC_RANGE)
        msg_puts(" range");
--- 1960,1978 ----
        }
      }
      msg_putchar(')');
! 
!     if (fp->uf_dfunc_idx >= 0)
!     {
!       if (fp->uf_ret_type != &t_void)
!       {
!           char *tofree;
! 
!           msg_puts(": ");
!           msg_puts(type_name(fp->uf_ret_type, &tofree));
!           vim_free(tofree);
!       }
!     }
!     else if (fp->uf_flags & FC_ABORT)
        msg_puts(" abort");
      if (fp->uf_flags & FC_RANGE)
        msg_puts(" range");
*** ../vim-8.2.0345/src/testdir/test_vim9_script.vim    2020-03-01 
17:55:09.005454943 +0100
--- src/testdir/test_vim9_script.vim    2020-03-01 23:30:10.392308591 +0100
***************
*** 66,71 ****
--- 66,74 ----
    let party1: partial
    let party2: partial = funcref('Test_syntax')
  
+   " type becomes list<any>
+   let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
+ 
    g:newvar = 'new'
    assert_equal('new', g:newvar)
  
*** ../vim-8.2.0345/src/testdir/runtest.vim     2019-11-30 22:40:44.000000000 
+0100
--- src/testdir/runtest.vim     2020-03-01 23:05:01.348574528 +0100
***************
*** 386,392 ****
  redir @q
  silent function /^Test_
  redir END
! let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
  
  " If there is an extra argument filter the function names against it.
  if argc() > 1
--- 386,392 ----
  redir @q
  silent function /^Test_
  redir END
! let s:tests = split(substitute(@q, '\(function\|def\) \(\k*()\)', '\2', 'g'))
  
  " If there is an extra argument filter the function names against it.
  if argc() > 1
*** ../vim-8.2.0345/src/testdir/test_vim9_disassemble.vim       2020-03-01 
17:55:09.009454927 +0100
--- src/testdir/test_vim9_disassemble.vim       2020-03-01 22:43:24.048788297 
+0100
***************
*** 814,817 ****
--- 814,849 ----
          \, res)
  enddef
  
+ def SomeStringArg(arg: string)
+   echo arg
+ enddef
+ 
+ def SomeAnyArg(arg: any)
+   echo arg
+ enddef
+ 
+ def SomeStringArgAndReturn(arg: string): string
+   return arg
+ enddef
+ 
+ def Test_display_func()
+   let res1 = execute('function SomeStringArg')
+   assert_match('.* def SomeStringArg(arg: string).*'
+         \ .. '  echo arg.*'
+         \ .. '  enddef'
+         \, res1)
+ 
+   let res2 = execute('function SomeAnyArg')
+   assert_match('.* def SomeAnyArg(arg: any).*'
+         \ .. '  echo arg.*'
+         \ .. '  enddef'
+         \, res2)
+ 
+   let res3 = execute('function SomeStringArgAndReturn')
+   assert_match('.* def SomeStringArgAndReturn(arg: string): string.*'
+         \ .. '  return arg.*'
+         \ .. '  enddef'
+         \, res3)
+ enddef
+ 
  " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.0345/src/version.c       2020-03-01 20:33:57.175639667 +0100
--- src/version.c       2020-03-01 21:57:24.386421425 +0100
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     346,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
155. You forget to eat because you're too busy surfing the net.

 /// 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/202003012233.021MXJZ9006139%40masaka.moolenaar.net.

Raspunde prin e-mail lui