[0.16.19] Minor Bug in lualib util.merge

This subforum contains all the issues which we already resolved.
blueblue
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Tue Apr 11, 2017 7:39 pm
Contact:

[0.16.19] Minor Bug in lualib util.merge

Post by blueblue »

The current merge function has inconsistent copying behavior for table members, it will sometimes deepcopy and at other times reference-copy. I am using the function to copy prototypes and make adjustments, and my modifications were sometimes affecting the original prototypes too.

Code: Select all

function util.merge(tables)
  local ret = {}
  for i, tab in ipairs(tables) do
    for k, v in pairs(tab) do
      if (type(v) == "table") and (type(ret[k] or false) == "table") then
        ret[k] = util.merge{ret[k], v}
-- Suggested addition start
      elseif type(v) == "table" then
        ret[k] = table.deepcopy(v)
-- Suggested addition end
      else
        ret[k] = v
      end
    end
  end
  return ret
end
unique_2 on discord and mod portal
posila
Factorio Staff
Factorio Staff
Posts: 5366
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.16.19] Minor Bug in lualib util.merge

Post by posila »

I though about it and concluded you are right. Implementation you proposed is more proper.

Thanks for the report.
Changed for 0.16.21
Post Reply

Return to “Resolved Problems and Bugs”