Patch 8.2.3263

4 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 31, 2021, 4:51:44 PM7/31/21
to vim...@googlegroups.com

Patch 8.2.3263
Problem: Vim9: "..=" does not accept same types as the ".." operator.
Solution: Convert value to string like ".." does. (issue #8664)
Files: src/vim9compile.c, src/testdir/test_vim9_assign.vim,
src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.3262/src/vim9compile.c 2021-07-28 21:25:45.356602806 +0200
--- src/vim9compile.c 2021-07-31 22:32:30.868941623 +0200
***************
*** 7086,7103 ****
type_T *stacktype;

if (*op == '.')
! expected = &t_string;
else
expected = lhs.lhs_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, 0, cctx,
FALSE, FALSE) == FAIL)
! goto theend;

if (*op == '.')
{
--- 7086,7108 ----
type_T *stacktype;

if (*op == '.')
! {
! if (may_generate_2STRING(-1, FALSE, cctx) == FAIL)
! goto theend;
! }
else
+ {
expected = lhs.lhs_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, 0, cctx,
FALSE, FALSE) == FAIL)
! goto theend;
! }

if (*op == '.')
{
*** ../vim-8.2.3262/src/testdir/test_vim9_assign.vim 2021-07-28 21:25:45.360602797 +0200
--- src/testdir/test_vim9_assign.vim 2021-07-31 22:41:15.279977366 +0200
***************
*** 239,244 ****
--- 239,270 ----
END
enddef

+ let g:someNumber = 43
+
+ def Test_assign_concat()
+ var lines =<< trim END
+ var s = '-'
+ s ..= 99
+ s ..= true
+ s ..= '-'
+ s ..= v:null
+ s ..= g:someNumber
+ assert_equal('-99true-null43', s)
+ END
+ CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
+ var s = '-'
+ s ..= [1, 2]
+ END
+ CheckDefAndScriptFailure2(lines, 'E1105: Cannot convert list to string', 'E734: Wrong variable type for .=', 2)
+ lines =<< trim END
+ var s = '-'
+ s ..= {a: 2}
+ END
+ CheckDefAndScriptFailure2(lines, 'E1105: Cannot convert dict to string', 'E734: Wrong variable type for .=', 2)
+ enddef
+
def Test_assign_register()
var lines =<< trim END
@c = 'areg'
*** ../vim-8.2.3262/src/testdir/test_vim9_disassemble.vim 2021-06-23 20:20:49.654780609 +0200
--- src/testdir/test_vim9_disassemble.vim 2021-07-31 22:48:34.051077563 +0200
***************
*** 1254,1260 ****
'res ..= str\_s*' ..
'\d\+ LOAD $0\_s*' ..
'\d\+ LOAD $2\_s*' ..
! '\d\+ CHECKTYPE string stack\[-1\]\_s*' ..
'\d\+ CONCAT\_s*' ..
'\d\+ STORE $0\_s*' ..
'endfor\_s*' ..
--- 1254,1260 ----
'res ..= str\_s*' ..
'\d\+ LOAD $0\_s*' ..
'\d\+ LOAD $2\_s*' ..
! '\d 2STRING_ANY stack\[-1\]\_s*' ..
'\d\+ CONCAT\_s*' ..
'\d\+ STORE $0\_s*' ..
'endfor\_s*' ..
*** ../vim-8.2.3262/src/version.c 2021-07-31 22:17:25.045867805 +0200
--- src/version.c 2021-07-31 22:50:36.446819489 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3263,
/**/

--
You cannot propel yourself forward by patting yourself on the back.

/// Bram Moolenaar -- Br...@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 ///

John Marriott

unread,
Jul 31, 2021, 5:17:09 PM7/31/21
to vim...@googlegroups.com

On 01-Aug-2021 06:51, Bram Moolenaar wrote:
> Patch 8.2.3263
> Problem: Vim9: "..=" does not accept same types as the ".." operator.
> Solution: Convert value to string like ".." does. (issue #8664)
> Files: src/vim9compile.c, src/testdir/test_vim9_assign.vim,
> src/testdir/test_vim9_disassemble.vim
>
After this patch mingw64 (gcc 11.2.0) spits out this warning:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD vim9compile.c -o
gobjnative/vim9compile.o
vim9compile.c: In function 'compile_assignment':
vim9compile.c:7114:21: warning: 'stacktype' may be used uninitialized in
this function [-Wmaybe-uninitialized]
 7114 |                 if (generate_add_instr(cctx,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~
 7115 | operator_type(lhs.lhs_member_type, stacktype),
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 7116 |                                        lhs.lhs_member_type,
stacktype) == FAIL)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</snip>

The attached patch tries to fix it.

Cheers
John
vim9compile.c.8.2.3263.patch
Reply all
Reply to author
Forward
0 new messages