fix(:let): fix error when applying operator to boolean option (#24030)

This commit is contained in:
zeertzjq 2023-06-15 12:36:21 +08:00 committed by GitHub
parent d81f78713b
commit 1f8fb7c000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -817,12 +817,11 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const,
new_n = num_modulus(cur_n, new_n); break;
}
// clamp boolean values
if (newval.type == kOptValTypeBoolean && (new_n > 1 || new_n < -1)) {
new_n = (new_n > 1) ? 1 : -1;
if (curval.type == kOptValTypeNumber) {
newval = NUMBER_OPTVAL(new_n);
} else {
newval = BOOLEAN_OPTVAL(new_n == 0 ? kFalse : (new_n >= 1 ? kTrue : kNone));
}
newval = kOptValTypeNumber ? NUMBER_OPTVAL(new_n) : BOOLEAN_OPTVAL((TriState)new_n);
} else if (!hidden && is_string
&& curval.data.string.data != NULL && newval.data.string.data != NULL) { // string
OptVal newval_old = newval;

View File

@ -92,6 +92,20 @@ describe(':let', function()
]])
eq(1, eval('1'))
end)
it('can apply operator to boolean option', function()
eq(true, meths.get_option_value('equalalways', {}))
command('let &equalalways -= 1')
eq(false, meths.get_option_value('equalalways', {}))
command('let &equalalways += 1')
eq(true, meths.get_option_value('equalalways', {}))
command('let &equalalways *= 1')
eq(true, meths.get_option_value('equalalways', {}))
command('let &equalalways /= 1')
eq(true, meths.get_option_value('equalalways', {}))
command('let &equalalways %= 1')
eq(false, meths.get_option_value('equalalways', {}))
end)
end)
describe(':let and :const', function()