From ce1154048b11cdc402d0e5da352a3adca19afb56 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 12 Mar 2026 15:04:05 +0000 Subject: refactor: integer functions, optimize asserts #34112 refactor(lua): add integer coercion helpers Add vim._tointeger() and vim._ensure_integer(), including optional base support, and switch integer-only tonumber()/assert call sites in the Lua runtime to use them. This also cleans up related integer parsing in LSP, health, loader, URI, tohtml, and Treesitter code. supported by AI --- runtime/lua/vim/func/_memoize.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'runtime/lua/vim/func/_memoize.lua') diff --git a/runtime/lua/vim/func/_memoize.lua b/runtime/lua/vim/func/_memoize.lua index c46f878067..c79ca596db 100644 --- a/runtime/lua/vim/func/_memoize.lua +++ b/runtime/lua/vim/func/_memoize.lua @@ -24,11 +24,15 @@ local function resolve_hash(hash) if type(hash) == 'number' then hash = idx_hash(hash) elseif type(hash) == 'string' then - local c = hash == 'concat' or hash:match('^concat%-(%d+)') - if c then - hash = concat_hash(tonumber(c)) + if hash == 'concat' then + hash = concat_hash() else - error('invalid value for hash: ' .. hash) + local c = hash:match('^concat%-(%d+)') + if c then + hash = concat_hash(vim._ensure_integer(c)) + else + error('invalid value for hash: ' .. hash) + end end end --- @cast hash -integer -- cgit