From ffa782066c2e02a068171963aded4bb300c25663 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 25 Sep 2026 17:07:21 +0100 Subject: fix(lua): enable assignment type checking in runtime code Enable EmmyLua's assign-type-mismatch diagnostic after correcting the runtime annotations and assignments it flags. Correct option, tuple, and return types, and use separate locals when a value changes representation. Add guards and narrow casts where needed so the runtime passes the stricter check. Regenerate the affected docs. AI-assisted --- runtime/lua/vim/version.lua | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'runtime/lua/vim/version.lua') diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua index a1c8137474..cf3662e177 100644 --- a/runtime/lua/vim/version.lua +++ b/runtime/lua/vim/version.lua @@ -68,7 +68,6 @@ local M = {} ---@field prerelease? string ---@field build? string local Version = {} -Version.__index = Version --- Compares prerelease strings: per semver, number parts must be must be treated as numbers: --- "pre1.10" is greater than "pre1.2". https://semver.org/#spec-item-11 @@ -180,12 +179,11 @@ function M._version(version, strict) -- Adapted from https://github.com/folke/la end if not strict then -- TODO: add more "scrubbing". - --- @cast version string - version = version:match('%d[^ ]*') - end - - if version == nil then - return nil + local scrubbed = version:match('%d[^ ]*') + if not scrubbed then + return nil + end + version = scrubbed end local prerel = version:match('%-([^+]*)') @@ -261,15 +259,15 @@ local VersionRange = {} --- @return boolean function VersionRange:has(version) if type(version) == 'string' then - ---@diagnostic disable-next-line: cast-local-type - version = M.parse(version) + local parsed = M.parse(version) + if not parsed then + return false + end + version = parsed elseif getmetatable(version) ~= Version then -- Need metatable to compare versions. version = setmetatable(vim.deepcopy(version, true), Version) end - if not version then - return false - end if self.from == self.to then return version == self.from end @@ -310,8 +308,8 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim to = rb and (#parts == 3 and rb.from or rb.to), }, range_mt) end - ---@type string, string local mods, version = spec:lower():match('^([%^=<>~]*)(.*)$') + assert(mods and version) -- The pattern matches every string. version = version:gsub('%.[%*x]', '') local parts = vim.split(version:gsub('%-.*', ''), '.', { plain = true }) if #parts < 3 and mods == '' then -- cgit