Patch 8.2.1490
Problem: Vim9: using /= with float and number doesn't work.
Solution: Better support assignment with operator. (closes #6742)
Files: src/vim9compile.c, src/testdir/test_vim9_script.vim
*** ../vim-8.2.1489/src/vim9compile.c 2020-08-16 18:29:31.480642573 +0200
--- src/vim9compile.c 2020-08-19 21:59:13.043706344 +0200
***************
*** 4923,4932 ****
lvar->lv_type = stacktype;
}
}
! else
{
type_T *use_type = lvar->lv_type;
if (has_index)
{
use_type = use_type->tt_member;
--- 4923,4933 ----
lvar->lv_type = stacktype;
}
}
! else if (*op == '=')
{
type_T *use_type = lvar->lv_type;
+ // without operator type is here, otherwise below
if (has_index)
{
use_type = use_type->tt_member;
***************
*** 4934,4940 ****
use_type = &t_void;
}
if (need_type(stacktype, use_type, -1, cctx, FALSE)
! == FAIL)
goto theend;
}
}
--- 4935,4941 ----
use_type = &t_void;
}
if (need_type(stacktype, use_type, -1, cctx, FALSE)
! == FAIL)
goto theend;
}
}
***************
*** 5008,5025 ****
if (oplen > 0 && *op != '=')
{
! type_T *expected = &t_number;
type_T *stacktype;
- // TODO: if type is known use float or any operation
- // TODO: check operator matches variable type
-
if (*op == '.')
expected = &t_string;
! else if (*op == '+')
expected = member_type;
stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
! if (need_type(stacktype, expected, -1, cctx, FALSE) == FAIL)
goto theend;
if (*op == '.')
--- 5009,5028 ----
if (oplen > 0 && *op != '=')
{
! type_T *expected;
type_T *stacktype;
if (*op == '.')
expected = &t_string;
! else
expected = member_type;
stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
! if (
! #ifdef FEAT_FLOAT
! // If variable is float operation with number is OK.
! !(expected == &t_float && stacktype == &t_number) &&
! #endif
! need_type(stacktype, expected, -1, cctx, FALSE) == FAIL)
goto theend;
if (*op == '.')
***************
*** 5034,5053 ****
member_type, stacktype) == FAIL)
goto theend;
}
! else
! {
! isn_T *isn = generate_instr_drop(cctx, ISN_OPNR, 1);
!
! if (isn == NULL)
! goto theend;
! switch (*op)
! {
! case '-': isn->isn_arg.op.op_type = EXPR_SUB; break;
! case '*': isn->isn_arg.op.op_type = EXPR_MULT; break;
! case '/': isn->isn_arg.op.op_type = EXPR_DIV; break;
! case '%': isn->isn_arg.op.op_type = EXPR_REM; break;
! }
! }
}
if (has_index)
--- 5037,5044 ----
member_type, stacktype) == FAIL)
goto theend;
}
! else if (generate_two_op(cctx, op) == FAIL)
! goto theend;
}
if (has_index)
*** ../vim-8.2.1489/src/testdir/test_vim9_script.vim 2020-08-16
21:29:01.982630120 +0200
--- src/testdir/test_vim9_script.vim 2020-08-19 22:01:45.891483430 +0200
***************
*** 90,95 ****
--- 90,107 ----
&ts %= 4
assert_equal(2, &ts)
+ if has('float')
+ let f100: float = 100.0
+ f100 /= 5
+ assert_equal(20.0, f100)
+
+ let f200: float = 200.0
+ f200 /= 5.0
+ assert_equal(40.0, f200)
+
+ CheckDefFailure(['let nr: number = 200', 'nr /= 5.0'], 'E1012:')
+ endif
+
lines =<< trim END
vim9script
&ts = 6
*** ../vim-8.2.1489/src/version.c 2020-08-19 21:20:46.089038670 +0200
--- src/version.c 2020-08-19 21:47:13.710836219 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1490,
/**/
--
If you're sending someone Styrofoam, what do you pack it in?
/// 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/202008192003.07JK3PcR010890%40masaka.moolenaar.net.