[16.16]util.merge attempt to call global merge (a nil value)

This subforum contains all the issues which we already resolved.
Roy
Inserter
Inserter
Posts: 26
Joined: Tue Jan 31, 2017 4:50 pm
Contact:

[16.16]util.merge attempt to call global merge (a nil value)

Post by Roy »

In util.lua there is a function called merge, it should merge two or more tables together. It works for the most part, except when having nested tables that need merging.

Code: Select all

/c game.print(serpent.block(util.merge(
{
	{
		a = { aa = 5 }
	}, 
	{
		a = { ab = 5 }
	}
})));
-- expected: { a = { ab = 5 }}
-- actually: Cannot execute command. Error: data/core/lualib/util.lua:206: attempt to call global 'merge' (a nil value)
The recursive call tries to call merge without util:

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] = merge{ret[k], v} --error message points to here
      else
        ret[k] = v
      end
    end
  end
  return ret
end
It should be:

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}
      else
        ret[k] = v
      end
    end
  end
  return ret
end
posila
Factorio Staff
Factorio Staff
Posts: 5371
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [16.16]util.merge attempt to call global merge (a nil value)

Post by posila »

Thanks for the report.
Fixed for 0.16.17
Post Reply

Return to “Resolved Problems and Bugs”