Patch 9.0.1436
Problem:    Cannot compare a typed variable with v:none.
Solution:   Allow for "x is v:none" and "x isnot v:none". (issue #12194)
Files:      src/vim9instr.c, src/vim9execute.c, src/testdir/test_vim9_func.vim


*** ../vim-9.0.1435/src/vim9instr.c     2023-02-27 08:07:10.873872843 +0000
--- src/vim9instr.c     2023-04-01 21:36:08.792457762 +0100
***************
*** 413,419 ****
   */
      static isntype_T
  get_compare_isn(
!       exprtype_T exprtype,
        typval_T    *tv1,
        typval_T    *tv2,
        type_T      *type1,
--- 413,419 ----
   */
      static isntype_T
  get_compare_isn(
!       exprtype_T  exprtype,
        typval_T    *tv1,
        typval_T    *tv2,
        type_T      *type1,
***************
*** 485,497 ****
        return ISN_DROP;
      }
      if (isntype == ISN_DROP
!           || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL
!                   && (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL
!                      || vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL)))
!           || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL
!                              && exprtype != EXPR_IS && exprtype != EXPR_ISNOT
!                   && (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB
!                       || vartype1 == VAR_LIST || vartype2 == VAR_LIST))))
      {
        semsg(_(e_cannot_compare_str_with_str),
                vartype_name(vartype1), vartype_name(vartype2));
--- 485,501 ----
        return ISN_DROP;
      }
      if (isntype == ISN_DROP
!           || (isntype != ISN_COMPARENULL
!               && (((exprtype != EXPR_EQUAL
!                       && exprtype != EXPR_NEQUAL
!                       && (vartype1 == VAR_BOOL || vartype1 == VAR_SPECIAL
!                         || vartype2 == VAR_BOOL || vartype2 == VAR_SPECIAL)))
!                   || ((exprtype != EXPR_EQUAL
!                        && exprtype != EXPR_NEQUAL
!                        && exprtype != EXPR_IS
!                        && exprtype != EXPR_ISNOT
!                        && (vartype1 == VAR_BLOB || vartype2 == VAR_BLOB
!                         || vartype1 == VAR_LIST || vartype2 == VAR_LIST))))))
      {
        semsg(_(e_cannot_compare_str_with_str),
                vartype_name(vartype1), vartype_name(vartype2));
*** ../vim-9.0.1435/src/vim9execute.c   2023-03-07 17:13:47.317107770 +0000
--- src/vim9execute.c   2023-04-01 21:57:37.762332584 +0100
***************
*** 3496,3502 ****
            case ISN_LOAD:
                if (GA_GROW_FAILS(&ectx->ec_stack, 1))
                    goto theend;
!               copy_tv(STACK_TV_VAR(iptr->isn_arg.number), STACK_TV_BOT(0));
                ++ectx->ec_stack.ga_len;
                break;
  
--- 3496,3510 ----
            case ISN_LOAD:
                if (GA_GROW_FAILS(&ectx->ec_stack, 1))
                    goto theend;
!               tv = STACK_TV_VAR(iptr->isn_arg.number);
!               if (tv->v_type == VAR_UNKNOWN)
!               {
!                   // missing argument or default value v:none
!                   STACK_TV_BOT(0)->v_type = VAR_SPECIAL;
!                   STACK_TV_BOT(0)->vval.v_number = VVAL_NONE;
!               }
!               else
!                   copy_tv(tv, STACK_TV_BOT(0));
                ++ectx->ec_stack.ga_len;
                break;
  
*** ../vim-9.0.1435/src/testdir/test_vim9_func.vim      2023-02-27 
22:06:48.276971827 +0000
--- src/testdir/test_vim9_func.vim      2023-04-01 22:03:58.891073185 +0100
***************
*** 752,757 ****
--- 752,782 ----
    v9.CheckScriptSuccess(lines)
  enddef
  
+ def Test_using_vnone_default()
+   var lines =<< trim END
+       vim9script
+ 
+       def F(a: string = v:none)
+          if a isnot v:none
+             var b = a
+          endif
+       enddef
+       F()
+   END
+   v9.CheckScriptSuccess(lines)
+ 
+   # TODO: this should give an error for using a missing argument
+   # lines =<< trim END
+   #    vim9script
+ 
+   #    def F(a: string = v:none)
+   #       var b = a
+   #    enddef
+   #    F()
+   # END
+   # v9.CheckScriptFailure(lines, 'E99:')
+ enddef
+ 
  def Test_convert_number_to_float()
    var lines =<< trim END
        vim9script
*** ../vim-9.0.1435/src/version.c       2023-04-01 19:54:36.452530922 +0100
--- src/version.c       2023-04-01 21:33:04.765204174 +0100
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1436,
  /**/

-- 
Seen on the back of a biker's vest: If you can read this, my wife fell off.

 /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230401210635.16E551C192B%40moolenaar.net.

Raspunde prin e-mail lui