rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
152 stars 47 forks source link

optionals, use question mark at the end of a var name to support assignment to invalid #16

Open ronenlh opened 4 years ago

ronenlh commented 4 years ago

Similar to Type Declaration Characters such as $ (String), % (Integer), ! (Float), # (Double), & (LongInteger), which don't allow assignments of invalid, we could make the language null-safe by never allowing assignments of invalid unless the var name ends with ? by creating a runtime error.

Like in Swift, this value could be an associative array with two possible values in it, none or some, with the associated value. (Swift does that with an Enum). To assign an optional to a non-optional, an unwrapping function is needed which releases the some value or provides an alternative if none is encountered.

ronenlh commented 4 years ago

this could be tied into https://github.com/TwitchBronBron/brighterscript/issues/8