mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2320: Vim9: no error for comparing bool with string
Problem: Vim9: no error for comparing bool with string. Solution: Check for wrong types when comparing. (closes #7639)
This commit is contained in:
24
src/typval.c
24
src/typval.c
@@ -834,6 +834,30 @@ typval_compare(
|
||||
default: break; // avoid gcc warning
|
||||
}
|
||||
}
|
||||
else if (in_vim9script() && (typ1->v_type == VAR_BOOL
|
||||
|| typ2->v_type == VAR_BOOL))
|
||||
{
|
||||
if (typ1->v_type != typ2->v_type)
|
||||
{
|
||||
semsg(_(e_cannot_compare_str_with_str),
|
||||
vartype_name(typ1->v_type), vartype_name(typ2->v_type));
|
||||
clear_tv(typ1);
|
||||
return FAIL;
|
||||
}
|
||||
n1 = typ1->vval.v_number;
|
||||
n2 = typ2->vval.v_number;
|
||||
switch (type)
|
||||
{
|
||||
case EXPR_IS:
|
||||
case EXPR_EQUAL: n1 = (n1 == n2); break;
|
||||
case EXPR_ISNOT:
|
||||
case EXPR_NEQUAL: n1 = (n1 != n2); break;
|
||||
default:
|
||||
emsg(_(e_invalid_operation_for_bool));
|
||||
clear_tv(typ1);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s1 = tv_get_string_buf(typ1, buf1);
|
||||
|
Reference in New Issue
Block a user