data:extend({nil}) does not error, but causes the NEXT prototype to fail to register

Things that we don't consider worth fixing at this moment.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 583
Joined: Tue May 19, 2015 1:56 am
Contact:

data:extend({nil}) does not error, but causes the NEXT prototype to fail to register

Post by Reika »

That is to say, if I have prototypes A, B, C, and D, and data:extend({a, b, c, d}), if b is nil, there is no error thrown at any point, but c also fails to be created in the game.
Image
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register

Post by Nexela »

Code: Select all

function data.extend(self, otherdata)
  if type(otherdata) ~= table_string or #otherdata == 0 then
    error("Invalid prototype array " .. serpent.block(otherdata, {maxlevel= 1}))
  end

  for _, e in ipairs(otherdata) do
Not a bug in the sense that it is doing what ipairs does by stopping iteration at the first nil. I wouldn't be surprised if rseding changes it to use pairs though, because pairs always works :)
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 583
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register

Post by Reika »

Nexela wrote: Thu Oct 18, 2018 1:38 am

Code: Select all

function data.extend(self, otherdata)
  if type(otherdata) ~= table_string or #otherdata == 0 then
    error("Invalid prototype array " .. serpent.block(otherdata, {maxlevel= 1}))
  end

  for _, e in ipairs(otherdata) do
Not a bug in the sense that it is doing what ipairs does by stopping iteration at the first nil. I wouldn't be surprised if rseding changes it to use pairs though, because pairs always works :)
At the very least, "nil" should throw an error as a prototype value, the way random garbage does.
Image
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register

Post by eradicator »

Reika wrote: Thu Oct 18, 2018 1:54 am At the very least, "nil" should throw an error as a prototype value, the way random garbage does.
You're basically calling data:extend{[1]=a,[2]=b,[4]=d}. Lua doesn't make a difference between you explicitly setting [3] to nil or if [3] just accidentially happens to be nil, same as for [5] and following.

Changing to pairs() sounds like a reasonable solution.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14598
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register

Post by Rseding91 »

Thanks for the report however I don't consider this worth adding a custom error for.

Currently even the "type" checks in data:extend have a measurable overhead to how long it takes prototypes to load. Since the *extreme* normal use-case is the inputs are correct I think it's fine if it doesn't handle "nicely" when they aren't.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Won't fix.”