fix(vim.version): fix metatable for intersections #41615

Problem:
`vim.version.intersect()` returns tables with `VersionRange` (method
table) as their metatable. Although the calculated bounds are correct,
the results do not expose `VersionRange` methods.

Solution:
Construct intersection tables with `range_mt`, matching
`vim.version.range()`. Add assertions covering method access and
repeated intersection.
This commit is contained in:
Volodymyr Chernetskyi
2026-09-02 16:10:18 +02:00
committed by GitHub
parent a41d008666
commit 8321941ff2
2 changed files with 7 additions and 3 deletions

View File

@@ -381,7 +381,7 @@ function M.intersect(r1, r2)
local from = r1.from <= r2.from and r2.from or r1.from
local to = (r1.to == nil or (r2.to ~= nil and r2.to <= r1.to)) and r2.to or r1.to
if to == nil or from < to or (from == to and r1:has(from) and r2:has(from)) then
return setmetatable({ from = from, to = to }, VersionRange)
return setmetatable({ from = from, to = to }, range_mt)
end
end