Suggestion - functions without a return statement should return undefined, not 0

Comments

8 comments

  • Julian Adams

    This was mooted some years ago prior to GMS2 iirc

    0
    Comment actions Permalink
  • Core Tech

    Hmmm I think this is something that could be done within the compiler... I will think about it over the festive period and see if I can come up with any issues around this.

    I cannot think of anything off the top of my head.

    Russell

    0
    Comment actions Permalink
  • Gabe Weiner

    Would love to see this!! For any folks strangely relying on this, undefined would still pass any "not" check -- I really doubt anyone is checking for "== false" on a script they didn't put a return in

    0
    Comment actions Permalink
  • Zach Reedy

    Yeah, checking the return value of a script (in 2.3 and earlier) that either exit'd or didn't explicitly return should probably be regarded as "undefined behavior" anyways, since to the best of my knowledge the return value in these cases was never explicitly defined as part of the language spec.

    0
    Comment actions Permalink
  • John Leffingwell

    Often this is explicitly undefined behavior. Of note is that it is undefined behavior in C languages but is the value `undefined` in JavaScript which might cause headaches for compiler makers or users relying on a specific outcome for more those platforms.

    Legacy (pre-Studio) GM would produce a value that usually equaled the last executed statement but was sometimes a mystery value that was neither real or string.

    0
    Comment actions Permalink
  • Julian Adams

    "I really doubt anyone is checking for "== false" on a script they didn't put a return in"

    *laughs in Rivals of Aether*

    0
    Comment actions Permalink
  • Gabe Weiner

    oh

    0
    Comment actions Permalink
  • Julian Adams

    They've gotta learn one way or another

    0
    Comment actions Permalink

Please sign in to leave a comment.