diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index fc993150a5..7d59f5e872 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -3246,7 +3246,7 @@ static Object opt_from_tv(typval_T *tv, OptIndex opt_idx, const char *option, bo const char *strval = tv_get_string_buf_chk(tv, nbuf); err = strval == NULL; value = CSTR_TO_OBJ(strval); - } else if (!is_tty_opt) { + } else { err = true; emsg(_(e_string_required)); } diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua index 1cd12f42d1..54153db049 100644 --- a/test/functional/vimscript/let_spec.lua +++ b/test/functional/vimscript/let_spec.lua @@ -114,6 +114,15 @@ describe(':let', function() command('let &equalalways %= 1') eq(false, api.nvim_get_option_value('equalalways', {})) end) + + it('assigning bool/special to a string option gives E928, not a crash', function() + for _, v in ipairs({ 'v:true', 'v:false', 'v:null' }) do + -- Regular string option. + eq('Vim(let):E928: String required', t.pcall_err(command, 'let &makeprg = ' .. v)) + -- TTY option ("t_" pseudo-option). + eq('Vim(let):E928: String required', t.pcall_err(command, 'let &t_Co = ' .. v)) + end + end) end) describe(':let and :const', function()