Compare commits

...

3 Commits

Author SHA1 Message Date
Bram Moolenaar
f5d52c90e0 patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Problem:    Vim9: "..=" does not accept same types as the ".." operator.
Solution:   Convert value to string like ".." does. (issue #8664)
2021-07-31 22:51:10 +02:00
Bram Moolenaar
9e0ee59019 patch 8.2.3262: build failure when ABORT_ON_INTERNAL_ERROR is defined
Problem:    Build failure when ABORT_ON_INTERNAL_ERROR is defined.
Solution:   Adjust how estack_len_before is used.
2021-07-31 22:17:28 +02:00
Bram Moolenaar
1780f08ba4 patch 8.2.3261: Vim9: when compiling repeat(123, N) return type is number
Problem:    Vim9: when compiling repeat(123, N) return type is number.
Solution:   Make return type a string. (closes #8664)
2021-07-31 22:03:59 +02:00
7 changed files with 62 additions and 13 deletions

View File

@@ -930,6 +930,13 @@ ret_first_arg(int argcount, type_T **argtypes)
if (argcount > 0)
return argtypes[0];
return &t_void;
}
static type_T *
ret_repeat(int argcount UNUSED, type_T **argtypes)
{
if (argtypes[0] == &t_number)
return &t_string;
return argtypes[0];
}
// for map(): returns first argument but item type may differ
static type_T *
@@ -1813,7 +1820,7 @@ static funcentry_T global_functions[] =
{"rename", 2, 2, FEARG_1, arg2_string,
ret_number_bool, f_rename},
{"repeat", 2, 2, FEARG_1, arg2_repeat,
ret_first_arg, f_repeat},
ret_repeat, f_repeat},
{"resolve", 1, 1, FEARG_1, arg1_string,
ret_string, f_resolve},
{"reverse", 1, 1, FEARG_1, arg1_list_or_blob,

View File

@@ -664,8 +664,6 @@ do_cmdline(
#endif
static int call_depth = 0; // recursiveness
#ifdef FEAT_EVAL
ESTACK_CHECK_DECLARATION
// For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory
// location for storing error messages to be converted to an exception.
// This ensures that the do_errthrow() call in do_one_cmd() does not
@@ -1397,6 +1395,7 @@ handle_did_throw()
{
char *p = NULL;
msglist_T *messages = NULL;
ESTACK_CHECK_DECLARATION
/*
* If the uncaught exception is a user exception, report it as an

View File

@@ -239,6 +239,32 @@ def Test_assignment()
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'

View File

@@ -2558,9 +2558,15 @@ enddef
def Test_repeat()
CheckDefAndScriptFailure2(['repeat(1.1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1224: String, Number or List required for argument 1')
CheckDefAndScriptFailure2(['repeat({a: 10}, 2)'], 'E1013: Argument 1: type mismatch, expected string but got dict<', 'E1224: String, Number or List required for argument 1')
assert_equal('aaa', repeat('a', 3))
assert_equal('111', repeat(1, 3))
assert_equal([1, 1, 1], repeat([1], 3))
var lines =<< trim END
assert_equal('aaa', repeat('a', 3))
assert_equal('111', repeat(1, 3))
assert_equal([1, 1, 1], repeat([1], 3))
var s = '-'
s ..= repeat(5, 3)
assert_equal('-555', s)
END
CheckDefAndScriptSuccess(lines)
enddef
def Test_resolve()

View File

@@ -1254,7 +1254,7 @@ def Test_disassemble_for_loop_eval()
'res ..= str\_s*' ..
'\d\+ LOAD $0\_s*' ..
'\d\+ LOAD $2\_s*' ..
'\d\+ CHECKTYPE string stack\[-1\]\_s*' ..
'\d 2STRING_ANY stack\[-1\]\_s*' ..
'\d\+ CONCAT\_s*' ..
'\d\+ STORE $0\_s*' ..
'endfor\_s*' ..

View File

@@ -755,6 +755,12 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3263,
/**/
3262,
/**/
3261,
/**/
3260,
/**/

View File

@@ -7086,18 +7086,23 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
type_T *stacktype;
if (*op == '.')
expected = &t_string;
{
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 (
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) &&
// 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;
goto theend;
}
if (*op == '.')
{