]> granicus.if.org Git - vim/commitdiff
patch 8.2.3296: Vim9: cannot add a number to a float v8.2.3296
authorBram Moolenaar <Bram@vim.org>
Thu, 5 Aug 2021 17:01:17 +0000 (19:01 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 Aug 2021 17:01:17 +0000 (19:01 +0200)
Problem:    Vim9: cannot add a number to a float.
Solution:   Accept a number if the destination is a float. (closes #8703)

src/testdir/test_vim9_assign.vim
src/version.c
src/vim9compile.c

index 428de1c1358765bcf651ddf44a9e3c2820baa1f3..8491a4d879ae9c926bd38e08a91213e97b262008 100644 (file)
@@ -245,6 +245,23 @@ def Test_assignment()
   END
 enddef
 
+def Test_float_and_number()
+  if !has('float')
+    MissingFeature float
+  else
+    var lines =<< trim END
+         var f: float
+         f += 2
+         f -= 1
+         assert_equal(1.0, f)
+         ++f
+         --f
+         assert_equal(1.0, f)
+    END
+    CheckDefAndScriptSuccess(lines)
+  endif
+enddef
+
 let g:someNumber = 43
 
 def Test_assign_concat()
index cc8300be63ea154663c7db04fcbe26f2ce8a56bd..c6852f1e72f4ad912a23d2fcca729c18800c20e9 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3296,
 /**/
     3295,
 /**/
index 1c6e328f00707ae43bcb0919f4a888474c31474b..d2a6f68db002c603770c54cd67b9b8bc5ea8bf82 100644 (file)
@@ -7021,8 +7021,10 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
 
                    // Special case: assigning to @# can use a number or a
                    // string.
-                   if (lhs_type == &t_number_or_string
-                                           && rhs_type->tt_type == VAR_NUMBER)
+                   // Also: can assign a number to a float.
+                   if ((lhs_type == &t_number_or_string
+                               || lhs_type == &t_float)
+                           && rhs_type->tt_type == VAR_NUMBER)
                        lhs_type = &t_number;
                    if (*p != '=' && need_type(rhs_type, lhs_type,
                                            -1, 0, cctx, FALSE, FALSE) == FAIL)