aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/version.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-03-06 15:08:22 +0100
committerJustin M. Keyes <justinkz@gmail.com>2023-03-06 15:36:25 +0100
commit74ffebf8ec725a25c2ae1dde81cf26b83fc7ae61 (patch)
treea6ef1d2c0195f9dd06109e0d977cb382c9b428df /runtime/lua/vim/version.lua
parente31e49a8e3aac25e923dce15cc76dca4a447947f (diff)
downloadrneovim-74ffebf8ec725a25c2ae1dde81cf26b83fc7ae61.tar.gz
rneovim-74ffebf8ec725a25c2ae1dde81cf26b83fc7ae61.tar.bz2
rneovim-74ffebf8ec725a25c2ae1dde81cf26b83fc7ae61.zip
fix(vim.version): incorrect version.cmp()
Problem: If major<major but minor>minor, cmp_version_core returns 1 Solution: - Fix logic in cmp_version_core - Delete most eq()/gt()/lt() tests, they are redundant.
Diffstat (limited to 'runtime/lua/vim/version.lua')
-rw-r--r--runtime/lua/vim/version.lua22
1 files changed, 10 insertions, 12 deletions
diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua
index ddbe228244..35629c461f 100644
--- a/runtime/lua/vim/version.lua
+++ b/runtime/lua/vim/version.lua
@@ -3,8 +3,11 @@ local M = {}
---@private
---@param version string
---@return string
-local function create_err_msg(version)
- return string.format('invalid version: "%s"', version)
+local function create_err_msg(v)
+ if type(v) == 'string' then
+ return string.format('invalid version: "%s"', tostring(v))
+ end
+ return string.format('invalid version: %s (%s)', tostring(v), type(v))
end
---@private
@@ -20,9 +23,6 @@ end
---@private
--- Compares the prerelease component of the two versions.
----@param v1 table Parsed version.
----@param v2 table Parsed version.
----@return integer `-1` if `v1 < v2`, `0` if `v1 == v2`, `1` if `v1 > v2`.
local function cmp_prerelease(v1, v2)
if v1.prerelease and not v2.prerelease then
return -1
@@ -88,19 +88,17 @@ local function cmp_prerelease(v1, v2)
end
---@private
---- Compares the version core component of the two versions.
----@param v1 table Parsed version.
----@param v2 table Parsed version.
----@return integer `-1` if `v1 < v2`, `0` if `v1 == v2`, `1` if `v1 > v2`.
local function cmp_version_core(v1, v2)
if v1.major == v2.major and v1.minor == v2.minor and v1.patch == v2.patch then
return 0
end
-
- if v1.major > v2.major or v1.minor > v2.minor or v1.patch > v2.patch then
+ if
+ v1.major > v2.major
+ or (v1.major == v2.major and v1.minor > v2.minor)
+ or (v1.major == v2.major and v1.minor == v2.minor and v1.patch > v2.patch)
+ then
return 1
end
-
return -1
end