misc.merge: ensure that misc.none is never returned (#441)

Before this change:

1. `misc.merge({a = misc.none}, {a = nil})` returned `{a = misc.none}`
2. `misc.merge({a = nil}, {a = misc.none})` returned `{a = misc.none}`

(1) can cause error if a non-existing mapping is set to `config.disable`
(which is an alias for `misc.none`).

(2) does not cause any issue to date, but is inconsistent with the
expected behavior of `misc.merge(…)`.

After this change:

1. `misc.merge({a = misc.none}, {a = nil})` returns `{a = nil}`
2. `misc.merge({a = nil}, {a = misc.none})` returns `{a = nil}`

Fixes #440.
This commit is contained in:
Charly Delay
2021-10-30 19:05:20 +09:00
committed by GitHub
parent 437074a303
commit b10bb327f3
2 changed files with 20 additions and 2 deletions

View File

@@ -46,7 +46,7 @@ misc.merge = function(v1, v2)
new_tbl[k] = misc.merge(v1[k], v)
end
for k, v in pairs(v1) do
if v2[k] == nil then
if v2[k] == nil and v ~= misc.none then
new_tbl[k] = v
end
end
@@ -56,8 +56,12 @@ misc.merge = function(v1, v2)
return nil
end
if v1 == nil then
if v2 == misc.none then
return nil
else
return v2
end
end
if v1 == true then
if merge2 then
return v2

View File

@@ -33,5 +33,19 @@ describe('misc', function()
},
})
assert.are.equal(merged.a, nil)
merged = misc.merge({
a = misc.none,
}, {
a = nil,
})
assert.are.equal(merged.a, nil)
merged = misc.merge({
a = nil,
}, {
a = misc.none,
})
assert.are.equal(merged.a, nil)
end)
end)