CommandHelper

CommandHelper

46.5k Downloads

Ambiguous behavior with "return(..)" vs "return ..."

LadyCailinBot opened this issue ยท 1 comments

commented

CMDHELPER-2820 - Reported by CyaNox

proc(_test1){
  @arr = array()
  if (array_index_exists(@arr, 0)){
    return null
  }
  return @arr[0] # IndexOverflowException
}

_test1()

proc(_test2){
  @arr = array()
  if (array_index_exists(@arr, 0)){
    return(null)
  }
  return @arr[0] # Not executed so no error.
}

_test2()

{code:title=Log}
22:05:17 [INFO] IndexOverflowException: The element at index "0" does not exist
proc _test1:/.../main.ms:6
<

>:/.../main.ms:9


I'm not sure if "return null" is actually supported syntactic sugar or if it is just plain wrong. Either way the behavior seems odd nonetheless. If it is wrong syntax then it should probably error there at compile time.
commented

Comment by LadyCailin

Unfortunately, there's no syntax sugar for that just yet, so it's taking the return to be a literal string. This is intended to be fixed in future versions with strict mode, but for now, I cannot deprecate that feature without breaking a ton of people's code, so I'm closing this as won't fix for now. Use parenthesis return(null) for returning.