Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
EnTerr
Level 8

`invalid` does not autobox?

This is "meta" by my own standards Smiley Happy - 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
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
Highlighted
EnTerr
Level 8

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" :mrgreenSmiley Happy if trying to use it.
0 Kudos
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