imported array()s being re-exported when changed in code.
LadyCailinBot opened this issue ยท 6 comments
CMDHELPER-2695 - Reported by Tom.Gebbett
running:
export('test',array())
@s = import('test')
msg(@s)
@s['a'] = 1
msg(import('test'))
echoes:
{}
{a: 1}
This means that the array, @s, was re-exported when array_set() was used.
I assume that this is because import/export values are treated the same way as ivars.
This may be deliberate, but it seems to me like a bug.
I can work around it, but it's not pleasant.
If this is intended, then consider this a request to document it.
Comment by LadyCailin
Hmm. This is an interesting problem that I hadn't directly thought of. What's happening is that it's not actually exporting the array as a value, but as a reference. I'll have to give this some more thought as to whether or not I want to change this behavior or not. In the meantime, you can use the array clone operator each time you export or import: @array = import('test')[]
Comment by LadyCailin
For more information: http://wiki.sk89q.com/wiki/CommandHelper/Arrays#Cloning_an_array
Comment by LadyCailin
Ok, after some more thought, I'm not going to change the behavior, because as you can see, it's easy enough to get around, and changing it would make it impossible to do references. In the case of persistance, you simply can't do that, so the arrays are inherently serialized, but that's different. I will update the documentation to mention this, however, and demonstrate the code needed to solve your problem.