From 75119fcc86e055895af824f7fdbba2f42c1cbbe8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:02:43 +0800 Subject: [PATCH 1/5] vim-patch:8.2.3135: Vim9: builtin function arguments not checked at compile time Problem: Vim9: builtin function arguments not checked at compile time. Solution: Add more type checks. (Yegappan Lakshmanan, closes vim/vim#8539) https://github.com/vim/vim/commit/5b73992d8f82be7ac4b6f46c17f53ffb9640e5fa Co-authored-by: Yegappan Lakshmanan --- src/nvim/eval/typval.c | 8 +-- test/functional/editor/mode_insert_spec.lua | 2 +- test/functional/legacy/edit_spec.lua | 2 +- test/functional/legacy/eval_spec.lua | 6 +-- test/functional/options/defaults_spec.lua | 4 +- test/functional/vimscript/execute_spec.lua | 10 ++-- test/functional/vimscript/input_spec.lua | 30 +++++------ test/functional/vimscript/writefile_spec.lua | 6 +-- test/old/testdir/test_search.vim | 12 ++--- test/unit/eval/typval_spec.lua | 52 ++++++++++---------- 10 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 79f514bc71..b4aa0bdeb0 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -3933,15 +3933,15 @@ bool tv_check_num(const typval_T *const tv) return false; } -#define FUNC_ERROR "E729: using Funcref as a String" +#define FUNC_ERROR "E729: Using a Funcref as a String" static const char *const str_errors[] = { [VAR_PARTIAL]= N_(FUNC_ERROR), [VAR_FUNC]= N_(FUNC_ERROR), - [VAR_LIST]= N_("E730: using List as a String"), - [VAR_DICT]= N_("E731: using Dictionary as a String"), + [VAR_LIST]= N_("E730: Using a List as a String"), + [VAR_DICT]= N_("E731: Using a Dictionary as a String"), [VAR_FLOAT]= e_float_as_string, - [VAR_BLOB]= N_("E976: using Blob as a String"), + [VAR_BLOB]= N_("E976: Using a Blob as a String"), [VAR_UNKNOWN]= e_inval_string, }; diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index 6f16b4e685..12f450520a 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -86,7 +86,7 @@ describe('insert-mode', function() {0:~ }| {4: }| ={2:{}} | - {5:E731: using Dictionary as a String} | + {5:E731: Using a Dictionary as a String} | {6:Press ENTER or type command to continue}^ | ]]) feed('') diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua index a0d8ca63a2..186bf395cc 100644 --- a/test/functional/legacy/edit_spec.lua +++ b/test/functional/legacy/edit_spec.lua @@ -95,7 +95,7 @@ describe('edit', function() {0:~ }| {4: }| ={2:{}} | - {5:E731: using Dictionary as a String} | + {5:E731: Using a Dictionary as a String} | {6:Press ENTER or type command to continue}^ | ]]) diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index b5e45a86c1..fc1343bb89 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -613,15 +613,15 @@ describe('eval', function() Executing call setreg(1, 2, 3, 4) Vim(call):E118: Too many arguments for function: setreg Executing call setreg([], 2) - Vim(call):E730: using List as a String + Vim(call):E730: Using a List as a String Executing call setreg(1, 2, []) - Vim(call):E730: using List as a String + Vim(call):E730: Using a List as a String Executing call setreg("/", ["1", "2"]) Vim(call):E883: search pattern and expression register may not contain two or more lines Executing call setreg("=", ["1", "2"]) Vim(call):E883: search pattern and expression register may not contain two or more lines Executing call setreg(1, ["", "", [], ""]) - Vim(call):E730: using List as a String]]) + Vim(call):E730: Using a List as a String]]) end) it('function name not starting with a capital', function() diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 4242b6e493..fcf313785a 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -892,8 +892,8 @@ describe('stdpath()', function() end) it('on non-strings', function() - eq('Vim(call):E731: using Dictionary as a String', exc_exec('call stdpath({"eris": 23})')) - eq('Vim(call):E730: using List as a String', exc_exec('call stdpath([23])')) + eq('Vim(call):E731: Using a Dictionary as a String', exc_exec('call stdpath({"eris": 23})')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call stdpath([23])')) end) end) end) diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index 5fe3d787cb..b9893a5150 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -95,15 +95,15 @@ describe('execute()', function() ret = exc_exec('call execute(0.0)') eq('Vim(call):E806: using Float as a String', ret) ret = exc_exec('call execute(v:_null_dict)') - eq('Vim(call):E731: using Dictionary as a String', ret) + eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(function("tr"))') - eq('Vim(call):E729: using Funcref as a String', ret) + eq('Vim(call):E729: Using a Funcref as a String', ret) ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])') eq('Vim:E806: using Float as a String', ret) ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])') - eq('Vim:E731: using Dictionary as a String', ret) + eq('Vim:E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])') - eq('Vim:E729: using Funcref as a String', ret) + eq('Vim:E729: Using a Funcref as a String', ret) end) it('captures output with highlights', function() @@ -325,7 +325,7 @@ describe('execute()', function() eq('Vim(call):E806: using Float as a String', ret) ret = exc_exec('call execute(v:_null_dict, "silent")') - eq('Vim(call):E731: using Dictionary as a String', ret) + eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute("echo add(1, 1)", "")') eq('Vim(echo):E897: List or Blob required', ret) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index f50b39c2c5..d1643a799a 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -222,17 +222,17 @@ describe('input()', function() eq('DEF2', meths.get_var('var')) end) it('errors out on invalid inputs', function() - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", "", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"prompt": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"default": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"completion": []})')) eq('Vim(call):E5050: {opts} must be the only argument', exc_exec('call input({}, "default")')) @@ -418,17 +418,17 @@ describe('inputdialog()', function() eq('DEF2', meths.get_var('var')) end) it('errors out on invalid inputs', function() - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", "", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"prompt": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"default": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"completion": []})')) eq('Vim(call):E5050: {opts} must be the only argument', exc_exec('call inputdialog({}, "default")')) @@ -512,13 +512,13 @@ describe('confirm()', function() eq(1, meths.get_var('a')) end - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm([])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm("Are you sure?", [])')) eq('Vim(call):E745: Using a List as a Number', pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", 0, [])')) end) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index c816efd37b..3cd1052968 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -147,11 +147,11 @@ describe('writefile()', function() for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do eq('Vim(call):E806: using Float as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) - eq('Vim(call):E731: using Dictionary as a String', + eq('Vim(call):E731: Using a Dictionary as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('{}')))) - eq('Vim(call):E729: using Funcref as a String', + eq('Vim(call):E729: Using a Funcref as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")')))) end eq('Vim(call):E5060: Unknown flag: «»', diff --git a/test/old/testdir/test_search.vim b/test/old/testdir/test_search.vim index 885043accf..37909d0afe 100644 --- a/test/old/testdir/test_search.vim +++ b/test/old/testdir/test_search.vim @@ -377,9 +377,9 @@ func Test_searchpairpos() endfunc func Test_searchpair_errors() - call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') - call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') - call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') + call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: Using a List as a String') + call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: Using a Funcref as a String') + call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: Using a Dictionary as a String') call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') @@ -388,9 +388,9 @@ func Test_searchpair_errors() endfunc func Test_searchpairpos_errors() - call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') - call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') - call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') + call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: Using a List as a String') + call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: Using a Funcref as a String') + call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: Using a Dictionary as a String') call assert_fails("call searchpairpos('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index ecee773ba8..59d150e63f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1468,10 +1468,10 @@ describe('typval.c', function() local l = list(1, empty_list, {}) eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) - eq('', tv_list_find_str(l, 1, 'E730: using List as a String')) - eq('', tv_list_find_str(l, 2, 'E731: using Dictionary as a String')) - eq('', tv_list_find_str(l, -1, 'E731: using Dictionary as a String')) - eq('', tv_list_find_str(l, -2, 'E730: using List as a String')) + eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) + eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, -3, 'E806: using Float as a String')) end) end) @@ -1745,7 +1745,7 @@ describe('typval.c', function() itp('works', function() local d = ffi.gc(dict({test={}}), nil) eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end, - 'E731: using Dictionary as a String'))) + 'E731: Using a Dictionary as a String'))) d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) alloc_log:clear() local dis = dict_items(d) @@ -1785,7 +1785,7 @@ describe('typval.c', function() return s_ret end local d = ffi.gc(dict({test={}}), nil) - eq('', tv_dict_get_string_alloc(d, 'test', 'E731: using Dictionary as a String')) + eq('', tv_dict_get_string_alloc(d, 'test', 'E731: Using a Dictionary as a String')) d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) alloc_log:clear() eq(nil, tv_dict_get_string_alloc(d, 'test')) @@ -2832,10 +2832,10 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, {lib.VAR_FLOAT, 'E806: using Float as a String'}, - {lib.VAR_PARTIAL, 'E729: using Funcref as a String'}, - {lib.VAR_FUNC, 'E729: using Funcref as a String'}, - {lib.VAR_LIST, 'E730: using List as a String'}, - {lib.VAR_DICT, 'E731: using Dictionary as a String'}, + {lib.VAR_PARTIAL, 'E729: Using a Funcref as a String'}, + {lib.VAR_FUNC, 'E729: Using a Funcref as a String'}, + {lib.VAR_LIST, 'E730: Using a List as a String'}, + {lib.VAR_DICT, 'E731: Using a Dictionary as a String'}, {lib.VAR_BOOL, nil}, {lib.VAR_SPECIAL, nil}, {lib.VAR_UNKNOWN, 'E908: using an invalid value as a String'}, @@ -2987,10 +2987,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', ''}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, @@ -3031,10 +3031,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', nil}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, @@ -3073,10 +3073,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', ''}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, @@ -3116,10 +3116,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', nil}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, From b8d5586d5b0d1e2d25533ee398d16bb2e8412820 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 08:18:36 +0800 Subject: [PATCH 2/5] refactor: using a different error number for 'mousescroll' Because E548 is linked to 'guicursor' in help. --- runtime/doc/options.txt | 2 +- src/nvim/optionstr.c | 2 +- test/functional/options/mousescroll_spec.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 324151ee58..c87b6f1835 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4254,7 +4254,7 @@ A jump table for the options with a short description can be found at |Q_op|. Warning: Setting this option can make pending mappings to be aborted when the mouse is moved. - *'mousescroll'* + *'mousescroll'* *E5080* 'mousescroll' string (default "ver:3,hor:6") global This option controls the number of lines / columns to scroll by when diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 96d383bbb1..28c0e3f97d 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -514,7 +514,7 @@ const char *did_set_mousescroll(optset_T *args FUNC_ATTR_UNUSED) // Verify that only digits follow the colon. for (size_t i = 4; i < length; i++) { if (!ascii_isdigit(string[i])) { - return N_("E548: digit expected"); + return N_("E5080: Digit expected"); } } diff --git a/test/functional/options/mousescroll_spec.lua b/test/functional/options/mousescroll_spec.lua index 5bff45a836..38a9692792 100644 --- a/test/functional/options/mousescroll_spec.lua +++ b/test/functional/options/mousescroll_spec.lua @@ -20,7 +20,7 @@ end describe("'mousescroll'", function() local invalid_arg = 'Vim(set):E474: Invalid argument: mousescroll=' - local digit_expected = 'Vim(set):E548: digit expected: mousescroll=' + local digit_expected = 'Vim(set):E5080: Digit expected: mousescroll=' local function should_fail(val, errorstr) eq(errorstr..val, exc_exec('set mousescroll='..val)) From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: [PATCH 3/5] vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/arglist.c | 4 +- src/nvim/autocmd.c | 5 ++- src/nvim/bufwrite.c | 23 +++++++---- src/nvim/cursor_shape.c | 6 ++- src/nvim/eval.c | 12 +++--- src/nvim/eval/executor.c | 3 +- src/nvim/eval/executor.h | 2 +- src/nvim/eval/funcs.c | 10 +++-- src/nvim/eval/typval.c | 18 +++++---- src/nvim/eval/vars.c | 8 +++- src/nvim/ex_cmds.c | 5 ++- src/nvim/ex_cmds2.c | 5 ++- src/nvim/ex_docmd.c | 32 ++++++++++------ src/nvim/ex_eval.c | 7 +++- src/nvim/file_search.c | 7 ++-- src/nvim/getchar.c | 4 +- src/nvim/globals.h | 7 +--- src/nvim/highlight_group.c | 21 +++++++--- src/nvim/mapping.c | 22 ++++++++--- src/nvim/memfile.c | 4 +- src/nvim/memline.c | 34 ++++++++++++----- src/nvim/normal.c | 4 +- src/nvim/ops.c | 6 ++- src/nvim/optionstr.c | 6 ++- src/nvim/regexp.c | 14 ++++++- src/nvim/regexp_bt.c | 10 ++--- src/nvim/regexp_nfa.c | 4 +- src/nvim/search.c | 11 ++++-- src/nvim/spellfile.c | 8 +++- src/nvim/syntax.c | 13 +++++-- src/nvim/tag.c | 38 +++++++++++-------- src/nvim/undo.c | 13 +++++-- src/nvim/usercmd.c | 10 +++-- test/functional/ex_cmds/highlight_spec.lua | 2 +- test/functional/legacy/eval_spec.lua | 4 +- test/functional/legacy/glob2regpat_spec.lua | 2 +- test/functional/lua/commands_spec.lua | 2 +- test/functional/ui/cmdline_highlight_spec.lua | 4 +- test/functional/ui/mouse_spec.lua | 2 +- test/functional/vimscript/execute_spec.lua | 6 +-- .../vimscript/map_functions_spec.lua | 4 +- test/functional/vimscript/null_spec.lua | 4 +- test/functional/vimscript/writefile_spec.lua | 2 +- test/unit/eval/typval_spec.lua | 36 +++++++++--------- 44 files changed, 287 insertions(+), 157 deletions(-) diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 284c94a712..74348052b0 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -63,6 +63,8 @@ typedef struct { # include "arglist.c.generated.h" #endif +static const char e_window_layout_changed_unexpectedly[] + = N_("E249: Window layout changed unexpectedly"); static const char e_cannot_change_arglist_recursively[] = N_("E1156: Cannot change the argument list recursively"); @@ -976,7 +978,7 @@ static void arg_all_open_windows(arg_all_state_T *aall, int count) aall->new_curwin = wp; aall->new_curtab = curtab; } else if (wp->w_frame->fr_parent != curwin->w_frame->fr_parent) { - emsg(_("E249: window layout changed unexpectedly")); + emsg(_(e_window_layout_changed_unexpectedly)); i = count; break; } else { diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index b5109b4b21..2d5d8e262b 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -56,6 +56,9 @@ # include "autocmd.c.generated.h" #endif +static const char e_autocommand_nesting_too_deep[] + = N_("E218: Autocommand nesting too deep"); + // Naming Conventions: // - general autocmd behavior start with au_ // - AutoCmd start with aucmd_ @@ -1589,7 +1592,7 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force // Allow nesting of autocommands, but restrict the depth, because it's // possible to create an endless loop. if (nesting == 10) { - emsg(_("E218: autocommand nesting too deep")); + emsg(_(e_autocommand_nesting_too_deep)); goto BYPASS_AU; } diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index de56c5c717..84c1276b8b 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -49,7 +49,16 @@ #include "nvim/undo.h" #include "nvim/vim.h" -static char *err_readonly = "is read-only (cannot override: \"W\" in 'cpoptions')"; +static const char *err_readonly = "is read-only (cannot override: \"W\" in 'cpoptions')"; +static const char e_patchmode_cant_touch_empty_original_file[] + = N_("E206: Patchmode: can't touch empty original file"); +static const char e_write_error_conversion_failed_make_fenc_empty_to_override[] + = N_("E513: Write error, conversion failed (make 'fenc' empty to override)"); +static const char e_write_error_conversion_failed_in_line_nr_make_fenc_empty_to_override[] + = N_("E513: Write error, conversion failed in line %" PRIdLINENR + " (make 'fenc' empty to override)"); +static const char e_write_error_file_system_full[] + = N_("E514: Write error (file system full?)"); static const char e_no_matching_autocommands_for_buftype_str_buffer[] = N_("E676: No matching autocommands for buftype=%s buffer"); @@ -1064,7 +1073,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (buf->b_ml.ml_mfp == NULL) { // This can happen during startup when there is a stray "w" in the // vimrc file. - emsg(_(e_emptybuf)); + emsg(_(e_empty_buffer)); return FAIL; } @@ -1685,20 +1694,18 @@ restore_backup: if (err.msg == NULL) { if (write_info.bw_conv_error) { if (write_info.bw_conv_error_lnum == 0) { - err = set_err(_("E513: write error, conversion failed " - "(make 'fenc' empty to override)")); + err = set_err(_(e_write_error_conversion_failed_make_fenc_empty_to_override)); } else { err = set_err(xmalloc(300)); err.alloc = true; vim_snprintf(err.msg, 300, // NOLINT(runtime/printf) - _("E513: write error, conversion failed in line %" PRIdLINENR - " (make 'fenc' empty to override)"), + _(e_write_error_conversion_failed_in_line_nr_make_fenc_empty_to_override), write_info.bw_conv_error_lnum); } } else if (got_int) { err = set_err(_(e_interr)); } else { - err = set_err(_("E514: write error (file system full?)")); + err = set_err(_(e_write_error_file_system_full)); } } @@ -1837,7 +1844,7 @@ restore_backup: || (empty_fd = os_open(org, O_CREAT | O_EXCL | O_NOFOLLOW, perm < 0 ? 0666 : (perm & 0777))) < 0) { - emsg(_("E206: patchmode: can't touch empty original file")); + emsg(_(e_patchmode_cant_touch_empty_original_file)); } else { close(empty_fd); } diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index f21e632036..428f9f28e4 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -26,6 +26,8 @@ # include "cursor_shape.c.generated.h" #endif +static const char e_digit_expected[] = N_("E548: Digit expected"); + /// Handling of cursor and mouse pointer shapes in various modes. cursorentry_T shape_table[SHAPE_IDX_COUNT] = { // Values are set by 'guicursor' and 'mouseshape'. @@ -101,7 +103,7 @@ Array mode_style_array(Arena *arena) /// @param what SHAPE_CURSOR or SHAPE_MOUSE ('mouseshape') /// /// @returns error message for an illegal option, NULL otherwise. -char *parse_shape_opt(int what) +const char *parse_shape_opt(int what) { char *colonp; char *commap; @@ -194,7 +196,7 @@ char *parse_shape_opt(int what) if (len != 0) { p += len; if (!ascii_isdigit(*p)) { - return N_("E548: digit expected"); + return e_digit_expected; } int n = getdigits_int(&p, false, 0); if (len == 3) { // "ver" or "hor" diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d9d4708b89..07f65bbf22 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -95,6 +95,8 @@ static const char e_cannot_index_special_variable[] static const char *e_nowhitespace = N_("E274: No white space allowed before parenthesis"); static const char *e_write2 = N_("E80: Error while writing: %s"); +static const char e_variable_nested_too_deep_for_making_copy[] + = N_("E698: Variable nested too deep for making a copy"); static const char *e_string_list_or_blob_required = N_("E1098: String, List or Blob required"); static const char e_expression_too_recursive_str[] = N_("E1169: Expression too recursive: %s"); static const char e_dot_can_only_be_used_on_dictionary_str[] @@ -1613,7 +1615,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const if (lp->ll_li == NULL) { tv_clear(&var2); if (!quiet) { - semsg(_(e_listidx), (int64_t)lp->ll_n1); + semsg(_(e_list_index_out_of_range_nr), (int64_t)lp->ll_n1); } return NULL; } @@ -1629,7 +1631,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const listitem_T *ni = tv_list_find(lp->ll_list, (int)lp->ll_n2); if (ni == NULL) { if (!quiet) { - semsg(_(e_listidx), (int64_t)lp->ll_n2); + semsg(_(e_list_index_out_of_range_nr), (int64_t)lp->ll_n2); } return NULL; } @@ -1642,7 +1644,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const } if (lp->ll_n2 < lp->ll_n1) { if (!quiet) { - semsg(_(e_listidx), (int64_t)lp->ll_n2); + semsg(_(e_list_index_out_of_range_nr), (int64_t)lp->ll_n2); } return NULL; } @@ -3567,7 +3569,7 @@ static int check_can_index(typval_T *rettv, bool evaluate, bool verbose) return FAIL; case VAR_FLOAT: if (verbose) { - emsg(_(e_float_as_string)); + emsg(_(e_using_float_as_string)); } return FAIL; case VAR_BOOL: @@ -7692,7 +7694,7 @@ int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *c int ret = OK; if (recurse >= DICT_MAXNEST) { - emsg(_("E698: variable nested too deep for making a copy")); + emsg(_(e_variable_nested_too_deep_for_making_copy)); return FAIL; } recurse++; diff --git a/src/nvim/eval/executor.c b/src/nvim/eval/executor.c index 9caea2fef1..7668fb129f 100644 --- a/src/nvim/eval/executor.c +++ b/src/nvim/eval/executor.c @@ -20,7 +20,8 @@ # include "eval/executor.c.generated.h" // IWYU pragma: export #endif -char *e_listidx = N_("E684: list index out of range: %" PRId64); +char *e_list_index_out_of_range_nr + = N_("E684: List index out of range: %" PRId64); /// Handle tv1 += tv2, -=, *=, /=, %=, .= /// diff --git a/src/nvim/eval/executor.h b/src/nvim/eval/executor.h index 3d789f76a5..42abf77f4a 100644 --- a/src/nvim/eval/executor.h +++ b/src/nvim/eval/executor.h @@ -3,7 +3,7 @@ #include "nvim/eval/typval.h" -extern char *e_listidx; +extern char *e_list_index_out_of_range_nr; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "eval/executor.h.generated.h" diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index f898063fb0..927c1b3d5c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -148,6 +148,8 @@ PRAGMA_DIAG_POP static const char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob"); static const char *e_invalwindow = N_("E957: Invalid window number"); +static const char e_invalid_submatch_number_nr[] + = N_("E935: Invalid submatch number: %d"); static const char *e_reduceempty = N_("E998: Reduce of an empty %s with no initial value"); static const char e_missing_function_argument[] = N_("E1132: Missing function argument"); @@ -928,7 +930,7 @@ static void f_count(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (!error) { li = tv_list_find(l, (int)idx); if (li == NULL) { - semsg(_(e_listidx), idx); + semsg(_(e_list_index_out_of_range_nr), idx); } } } @@ -1902,7 +1904,7 @@ static void extend(typval_T *argvars, typval_T *rettv, char *arg_errmsg, bool is } else { item = tv_list_find(l1, (int)before); if (item == NULL) { - semsg(_(e_listidx), (int64_t)before); + semsg(_(e_list_index_out_of_range_nr), (int64_t)before); return; } } @@ -3729,7 +3731,7 @@ static void f_insert(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (before != tv_list_len(l)) { item = tv_list_find(l, (int)before); if (item == NULL) { - semsg(_(e_listidx), before); + semsg(_(e_list_index_out_of_range_nr), before); l = NULL; } } @@ -8027,7 +8029,7 @@ static void f_submatch(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (no < 0 || no >= NSUBEXP) { - semsg(_("E935: invalid submatch number: %d"), no); + semsg(_(e_invalid_submatch_number_nr), no); return; } int retList = 0; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index b4aa0bdeb0..5f0c082ada 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -40,6 +40,10 @@ # include "eval/typval.c.generated.h" #endif +static const char e_variable_nested_too_deep_for_unlock[] + = N_("E743: Variable nested too deep for (un)lock"); +static const char e_using_invalid_value_as_string[] + = N_("E908: Using an invalid value as a String"); static const char e_string_required_for_argument_nr[] = N_("E1174: String required for argument %d"); static const char e_non_empty_string_required_for_argument_nr[] @@ -793,7 +797,7 @@ int tv_list_slice_or_index(list_T *list, bool range, varnumber_T n1_arg, varnumb // A list index out of range is an error. if (!range) { if (verbose) { - semsg(_(e_listidx), (int64_t)n1); + semsg(_(e_list_index_out_of_range_nr), (int64_t)n1); } return FAIL; } @@ -987,7 +991,7 @@ void tv_list_remove(typval_T *argvars, typval_T *rettv, const char *arg_errmsg) if (error) { // Type error: do nothing, errmsg already given. } else if ((item = tv_list_find(l, (int)idx)) == NULL) { - semsg(_(e_listidx), idx); + semsg(_(e_list_index_out_of_range_nr), idx); } else { if (argvars[2].v_type == VAR_UNKNOWN) { // Remove one item, return its value. @@ -1001,7 +1005,7 @@ void tv_list_remove(typval_T *argvars, typval_T *rettv, const char *arg_errmsg) if (error) { // Type error: do nothing. } else if ((item2 = tv_list_find(l, (int)end)) == NULL) { - semsg(_(e_listidx), end); + semsg(_(e_list_index_out_of_range_nr), end); } else { int cnt = 0; @@ -1575,7 +1579,7 @@ const char *tv_list_find_str(list_T *const l, const int n) { const listitem_T *const li = tv_list_find(l, n); if (li == NULL) { - semsg(_(e_listidx), (int64_t)n); + semsg(_(e_list_index_out_of_range_nr), (int64_t)n); return NULL; } return tv_get_string(TV_LIST_ITEM_TV(li)); @@ -3583,7 +3587,7 @@ void tv_item_lock(typval_T *const tv, const int deep, const bool lock, const boo static int recurse = 0; if (recurse >= DICT_MAXNEST) { - emsg(_("E743: variable nested too deep for (un)lock")); + emsg(_(e_variable_nested_too_deep_for_unlock)); return; } if (deep == 0) { @@ -3940,9 +3944,9 @@ static const char *const str_errors[] = { [VAR_FUNC]= N_(FUNC_ERROR), [VAR_LIST]= N_("E730: Using a List as a String"), [VAR_DICT]= N_("E731: Using a Dictionary as a String"), - [VAR_FLOAT]= e_float_as_string, + [VAR_FLOAT]= e_using_float_as_string, [VAR_BLOB]= N_("E976: Using a Blob as a String"), - [VAR_UNKNOWN]= e_inval_string, + [VAR_UNKNOWN]= e_using_invalid_value_as_string, }; #undef FUNC_ERROR diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index de6c4bab60..64177d13e8 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -52,6 +52,10 @@ static const char *e_letunexp = N_("E18: Unexpected characters in :let"); static const char *e_lock_unlock = N_("E940: Cannot lock or unlock variable %s"); +static const char e_setting_str_to_value_with_wrong_type[] + = N_("E963: Setting %s to value with wrong type"); +static const char e_cannot_use_heredoc_here[] + = N_("E991: Cannot use =<< here"); /// Evaluate one Vim expression {expr} in string "p" and append the /// resulting string to "gap". "p" points to the opening "{". @@ -169,7 +173,7 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get) char dot[] = "."; if (eap->getline == NULL) { - emsg(_("E991: cannot use =<< here")); + emsg(_(e_cannot_use_heredoc_here)); return NULL; } @@ -1457,7 +1461,7 @@ void set_var_const(const char *name, const size_t name_len, typval_T *const tv, } return; } else if (v->di_tv.v_type != tv->v_type) { - semsg(_("E963: setting %s to value with wrong type"), name); + semsg(_(e_setting_str_to_value_with_wrong_type), name); return; } } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 2c31f742c3..dbfd1088d2 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -126,6 +126,9 @@ typedef struct { # include "ex_cmds.c.generated.h" #endif +static const char e_non_numeric_argument_to_z[] + = N_("E144: Non-numeric argument to :z"); + /// ":ascii" and "ga" implementation void do_ascii(const exarg_T *const eap) { @@ -2952,7 +2955,7 @@ void ex_z(exarg_T *eap) if (*x != 0) { if (!ascii_isdigit(*x)) { - emsg(_("E144: non-numeric argument to :z")); + emsg(_(e_non_numeric_argument_to_z)); return; } bigness = atol(x); diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index deaa24452b..40259767ff 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -53,6 +53,9 @@ # include "ex_cmds2.c.generated.h" #endif +static const char e_compiler_not_supported_str[] + = N_("E666: Compiler not supported: %s"); + void ex_ruby(exarg_T *eap) { script_host_execute("ruby", eap); @@ -731,7 +734,7 @@ void ex_compiler(exarg_T *eap) // Try lua compiler snprintf(buf, bufsize, "compiler/%s.lua", eap->arg); if (source_runtime(buf, DIP_ALL) == FAIL) { - semsg(_("E666: compiler not supported: %s"), eap->arg); + semsg(_(e_compiler_not_supported_str), eap->arg); } } xfree(buf); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0e6d4bba1b..bccd554095 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -87,12 +87,22 @@ static const char e_ambiguous_use_of_user_defined_command[] = N_("E464: Ambiguous use of user-defined command"); +static const char e_no_call_stack_to_substitute_for_stack[] + = N_("E489: No call stack to substitute for \"\""); static const char e_not_an_editor_command[] = N_("E492: Not an editor command"); +static const char e_no_autocommand_file_name_to_substitute_for_afile[] + = N_("E495: No autocommand file name to substitute for \"\""); +static const char e_no_autocommand_buffer_name_to_substitute_for_abuf[] + = N_("E496: No autocommand buffer number to substitute for \"\""); +static const char e_no_autocommand_match_name_to_substitute_for_amatch[] + = N_("E497: No autocommand match name to substitute for \"\""); static const char e_no_source_file_name_to_substitute_for_sfile[] - = N_("E498: no :source file name to substitute for \"\""); -static const char e_no_call_stack_to_substitute_for_stack[] - = N_("E489: no call stack to substitute for \"\""); + = N_("E498: No :source file name to substitute for \"\""); +static const char e_no_line_number_to_use_for_slnum[] + = N_("E842: No line number to use for \"\""); +static const char e_no_line_number_to_use_for_sflnum[] + = N_("E961: No line number to use for \"\""); static const char e_no_script_file_name_to_substitute_for_script[] = N_("E1274: No script file name to substitute for \"