0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3176: Vim9: no type error for comparing number with string

Problem:    Vim9: no type error for comparing number with string.
Solution:   Add a runtime type check. (closes #8571)
This commit is contained in:
Bram Moolenaar
2021-07-18 14:43:43 +02:00
parent c6ba2f9dde
commit 0c35752d04
4 changed files with 41 additions and 4 deletions

View File

@@ -937,7 +937,9 @@ typval_compare(
}
}
else if (in_vim9script() && (typ1->v_type == VAR_BOOL
|| typ2->v_type == VAR_BOOL))
|| typ2->v_type == VAR_BOOL
|| (typ1->v_type == VAR_SPECIAL
&& typ2->v_type == VAR_SPECIAL)))
{
if (typ1->v_type != typ2->v_type)
{
@@ -955,13 +957,23 @@ typval_compare(
case EXPR_ISNOT:
case EXPR_NEQUAL: n1 = (n1 != n2); break;
default:
emsg(_(e_invalid_operation_for_bool));
semsg(_(e_invalid_operation_for_str),
vartype_name(typ1->v_type));
clear_tv(typ1);
return FAIL;
}
}
else
{
if (in_vim9script()
&& ((typ1->v_type != VAR_STRING && typ1->v_type != VAR_SPECIAL)
|| (typ2->v_type != VAR_STRING && typ2->v_type != VAR_SPECIAL)))
{
semsg(_(e_cannot_compare_str_with_str),
vartype_name(typ1->v_type), vartype_name(typ2->v_type));
clear_tv(typ1);
return FAIL;
}
s1 = tv_get_string_buf(typ1, buf1);
s2 = tv_get_string_buf(typ2, buf2);
if (type != EXPR_MATCH && type != EXPR_NOMATCH)