CommandHelper

CommandHelper

46.5k Downloads

strange bug with procedure arguments when the ivars have certain names

LadyCailinBot opened this issue ยท 2 comments

commented

CMDHELPER-2813 - Reported by Tom.Gebbett

With these two procedures defined:

proc('_argstest',@wd,
    msg(@arguments)
)
proc('_argstest2',@a,
    msg(@arguments)
)

Run this code from a bind in main.ms:

_argstest()
_argstest2()

Echoes:

{surv}
{}

The second procedure is echoing the arguments array correctly, as being an empty array.
However, the first procedure adds the name of the last world in the get_worlds() list, in this case 'surv'.

This is due to the name of the argument, @wd. I almost always use @wd for storing the relevant world.
This happens no matter how many arguments there are in a procedure, the world is always added as the last argument.
The ivar @wd in the first procedure does actually contain 'surv'. There is absolutely no way that I manually passed this in.
It's likely that I am using 'surv' in some sort of other procedure, and it's somehow leaking here; although to be honest, it's not used often, and I don't know what would reference it.

There is an even stranger bug, which is probably related, demonstrated in this example:

proc('_argstest',@pl,@2,@3,@wd,
    msg(@arguments)
    msg('{'.@pl.', '.@2.', '.@3.', '.@wd.'}')
)

I've added formatting to make the outputs of both these msg() calls look the same, if the values given are the same. They should always be identical.

I then run this, as before.

_argstest()

It echoes:

{, , surv, }
{, , , surv}

This means that the last argument has shifted left one in the arguments array.

Another few scenarios that I tested:

@pl,@pl,@1,@wd = {, surv, }{, , , surv}
@wd,@1,@2,@wd = {, , surv}{, , , surv}
@wd,@1,@2,@pl = {, , , surv}{, , , surv}
@1,@wd,@2,@pl = {, , , surv}{, , , surv}
@wd,@wd,@wd,@wd = {surv}{, , , surv}

Calling the _argstest() proc from within another proc acts as it should, but the proc you call it from takes on the extra arguments.

I am using CommandHelper build 2417. It's not the latest, but the one just before the build that mentions 1.7. I thought I clicked 2418, but the plugin.yml says 2417. I'm not sure if this bug has been fixed in newer versions, but I did check the builds and nothing related seemed to be there.

As far as I know, i'm not doing anything that could store these variables in any way other than the intended method. I know I'm not using export(@wd) anywhere. There's probably something somewhere causing it to leak.

WORKAROUND for those who may be experiencing this too: You'll have to give empty strings (void) for all unused arguments in procedure calls. Unless you want to use different ivar names for every procedure.

commented

Comment by LadyCailin

Fixed in next build

commented

Comment by Tom.Gebbett

Thank you.