Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Roku Guru

`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.
0 Kudos
3 REPLIES 3
RokuKC
Roku Employee
Roku Employee

Re: `invalid` does not autobox?

"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.
0 Kudos
EnTerr
Roku Guru

Re: `invalid` does not autobox?

"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.
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: `invalid` does not autobox?

"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.
0 Kudos