Forum Discussion

EnTerr's avatar
EnTerr
Roku Guru
9 years ago

`invalid` does not autobox?

This is "meta" by my own standards 🙂 - but shouldn't `invalid` auto-box to `roInvalid` as needed, as the rest of the value-types do?

i see that roInvalid implements ifToStr, i presume to allow calling toStr() on all objects and get something printable w/o worrying to check for special cases first. i don't even know why roInvalid exists in the first place (a guess - so it can be stored in roArray, historically?) - but all other primitive types already tend to auto-box themselves "as needed" and invalid doesn't. Shouldn't it, too?

I am not sure which way is right, just pointing out what seems like a discrepancy.

3 Replies

  • RokuKC's avatar
    RokuKC
    Roku Employee
    "EnTerr" wrote:
    ... all other primitive types already tend to auto-box themselves "as needed" and invalid doesn't. Shouldn't it, too?


    The behavior is intentional. Invalid is invalid.
  • "RokuKC" wrote:
    The behavior is intentional.  Invalid is invalid.

    Hmm, but:
    Brightscript Debugger> ? getInterface(invalid, "ifToStr")
    <Interface: ifToStr>

    Brightscript Debugger> ? (invalid).toStr()
    'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in $LIVECOMPILE(254)

    So i can get ifToStr on invalid "no problema" but get spanked (runtime error "heck" :mrgreen:) if trying to use it.
  • RokuKC's avatar
    RokuKC
    Roku Employee
    "EnTerr" wrote:

    [code]Brightscript Debugger> ? getInterface(invalid, "ifToStr")
    <Interface: ifToStr>


    Yes, I can see why that is confusing. GetInterface() is defined as taking an object, so it boxes whatever is passed to it.