fix: treat unset properties as nil

Sometimes, the behaviour of function calls like `<plugin>.setup(arg)`
differs for `arg = nil` and `arg = {}`.

To cover both cases, treat unset plugin spec properties as `nil`.  For
the latter case, one may set `<prop> = {}` explicitly.
This commit is contained in:
Benedikt Rips 2023-02-14 12:28:13 +01:00
commit 21049241a4
No known key found for this signature in database
GPG key ID: ED7FCB814CB6C157

View file

@ -415,8 +415,8 @@ end
---@param prop string
---@param is_list? boolean
function M.values(plugin, prop, is_list)
---@type table
local ret = plugin._.super and M.values(plugin._.super, prop) or {}
---@type table | nil
local ret = plugin._.super and M.values(plugin._.super, prop)
local values = rawget(plugin, prop)
if not values then
@ -427,7 +427,7 @@ function M.values(plugin, prop, is_list)
end
values = type(values) == "table" and values or { values }
return is_list and Util.extend(ret, values) or Util.merge(ret, values)
return is_list and Util.extend(ret or {}, values) or Util.merge(ret, values)
end
return M