Skip to content

Commit af647e7

Browse files
committed
patch 8.2.3296: Vim9: cannot add a number to a float
Problem: Vim9: cannot add a number to a float. Solution: Accept a number if the destination is a float. (closes #8703)
1 parent 4f33bc2 commit af647e7

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/testdir/test_vim9_assign.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,23 @@ def Test_assignment()
245245
END
246246
enddef
247247

248+
def Test_float_and_number()
249+
if !has('float')
250+
MissingFeature float
251+
else
252+
var lines =<< trim END
253+
var f: float
254+
f += 2
255+
f -= 1
256+
assert_equal(1.0, f)
257+
++f
258+
--f
259+
assert_equal(1.0, f)
260+
END
261+
CheckDefAndScriptSuccess(lines)
262+
endif
263+
enddef
264+
248265
let g:someNumber = 43
249266

250267
def Test_assign_concat()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3296,
758760
/**/
759761
3295,
760762
/**/

src/vim9compile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7021,8 +7021,10 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
70217021

70227022
// Special case: assigning to @# can use a number or a
70237023
// string.
7024-
if (lhs_type == &t_number_or_string
7025-
&& rhs_type->tt_type == VAR_NUMBER)
7024+
// Also: can assign a number to a float.
7025+
if ((lhs_type == &t_number_or_string
7026+
|| lhs_type == &t_float)
7027+
&& rhs_type->tt_type == VAR_NUMBER)
70267028
lhs_type = &t_number;
70277029
if (*p != '=' && need_type(rhs_type, lhs_type,
70287030
-1, 0, cctx, FALSE, FALSE) == FAIL)

0 commit comments

Comments
 (0)