rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
158 stars 46 forks source link

Implement primitive type narrowing for global functions #1121

Open TwitchBronBron opened 5 months ago

TwitchBronBron commented 5 months ago

Add some very primitive type narrowing for global functions.

General syntax:

if type(doSomething) = "roFunction" then
    doSomething()
end if

You must wrap your function with an if statement that includes one or both of these conditions, but must contain no other conditions. Like this:

if type(theThing) = "roFunction"
if type(theThing) = "Function"
if type(theThing) = "roFunction"  or type(theThing) = "Function"

The order may also be swapped. Like this:

if type(theThing) = "roFunction"
if "roFunction" = type(theThing)

The way we will implement this in v0 is:

NOTE: this is NOT a broad type guard implementation, and is exclusively for global functions