Patch 8.2.2210
Problem:    Vim9: allocating a type to set TTFLAG_BOOL_OK.
Solution:   Add t_number_bool.
Files:      src/globals.h, src/vim9type.c, src/vim9compile.c


*** ../vim-8.2.2209/src/globals.h       2020-12-21 19:59:04.573197707 +0100
--- src/globals.h       2020-12-25 13:04:46.142167317 +0100
***************
*** 403,408 ****
--- 403,409 ----
  EXTERN type_T t_bool INIT6(VAR_BOOL, 0, 0, TTFLAG_STATIC, NULL, NULL);
  EXTERN type_T t_special INIT6(VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL);
  EXTERN type_T t_number INIT6(VAR_NUMBER, 0, 0, TTFLAG_STATIC, NULL, NULL);
+ EXTERN type_T t_number_bool INIT6(VAR_NUMBER, 0, 0, 
TTFLAG_STATIC|TTFLAG_BOOL_OK, NULL, NULL);
  EXTERN type_T t_float INIT6(VAR_FLOAT, 0, 0, TTFLAG_STATIC, NULL, NULL);
  EXTERN type_T t_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL);
  EXTERN type_T t_blob INIT6(VAR_BLOB, 0, 0, TTFLAG_STATIC, NULL, NULL);
*** ../vim-8.2.2209/src/vim9type.c      2020-12-25 12:37:59.487073428 +0100
--- src/vim9type.c      2020-12-25 13:06:39.921811367 +0100
***************
*** 376,393 ****
      if (type != NULL && type != &t_bool
            && (tv->v_type == VAR_NUMBER
                    && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
!     {
!       type_T *newtype = get_type_ptr(type_gap);
! 
!       // Number 0 and 1 and expression with "&&" or "||" can also be used
!       // for bool.
!       if (newtype != NULL)
!       {
!           *newtype = *type;
!           newtype->tt_flags = TTFLAG_BOOL_OK;
!           type = newtype;
!       }
!     }
      return type;
  }
  
--- 376,384 ----
      if (type != NULL && type != &t_bool
            && (tv->v_type == VAR_NUMBER
                    && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
!       // Number 0 and 1 and expression with "&&" or "||" can also be used for
!       // bool.
!       type = &t_number_bool;
      return type;
  }
  
*** ../vim-8.2.2209/src/vim9compile.c   2020-12-25 12:37:59.483073439 +0100
--- src/vim9compile.c   2020-12-25 13:07:23.793688631 +0100
***************
*** 931,947 ****
      isn->isn_arg.number = number;
  
      if (number == 0 || number == 1)
-     {
-       type_T  *type = get_type_ptr(cctx->ctx_type_list);
- 
        // A 0 or 1 number can also be used as a bool.
!       if (type != NULL)
!       {
!           type->tt_type = VAR_NUMBER;
!           type->tt_flags = TTFLAG_BOOL_OK;
!           ((type_T **)stack->ga_data)[stack->ga_len - 1] = type;
!       }
!     }
      return OK;
  }
  
--- 931,938 ----
      isn->isn_arg.number = number;
  
      if (number == 0 || number == 1)
        // A 0 or 1 number can also be used as a bool.
!       ((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_number_bool;
      return OK;
  }
  
*** ../vim-8.2.2209/src/version.c       2020-12-25 12:37:59.487073428 +0100
--- src/version.c       2020-12-25 13:20:21.039389095 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2210,
  /**/

-- 
I have a drinking problem -- I don't have a drink!

 /// 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/202012251221.0BPCLAwd3488436%40masaka.moolenaar.net.

Raspunde prin e-mail lui