CommandHelper

CommandHelper

46.5k Downloads

Incorrect initialization @arguments with default values

Anatoliy057 opened this issue · 2 comments

commented

Detected errors:

  • Wrong sequence
  • If the argument is type, then it takes the value UNDEFINED else an empty string

I’m not sure if these are errors, but I’ll mention:

  • The undefined argument takes the value of an empty string, although I think it should be null
  • Default values do not work in case of "closure"

Example code:

proc _test1(string @example, @double = 1.2, @int = 3, @string = 'end', @null) {
    console(@arguments, false)
    console(@double, false)
}

proc _test2(@example, @double = 1.2, @int = 3, @string = 'end', @null) {
    console(@arguments, false)
    console(@double, false)
}

proc _test3(@double = 1.2, @int = 3, @string = 'end') {
    console(@arguments, false)
    console(@double, false)
}

_test1('example_1')
_test2('example_2')
_test3('example_3')

Out:

{example_1, end, 1.2, null, }
1.2

{example_2, end, 1.2, , }
1.2

{example_3, end, 1.2}
example_3
commented

Fixed in 18d26d2.

commented

This is caused by looping over the HashSet of variables (undefined order) in combination with using push(), rather than some set(index, ...) for generating @arguments. That happens on this line:
https://github.com/EngineHub/CommandHelper/blob/master/src/main/java/com/laytonsmith/core/Procedure.java#L196