-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Milestone
Description
It would be extremely useful to allow invalid as a type, for cases like the one below:
interface ISomething
id as String
name as String
value as Integer
end interface
'...
myMapOfThings = {} ' as Dictionary<string, ISomething>
function getSomething(id as String) as ISomething or invalid
' The "id" might not exist in the map, leading to this function returning `invalid`.
' If I can't specify that `invalid` can be returned, then the user might assume that
' it always returns something, and then have the Roku crash when attempting to use it.
return m.myMapOfThings[id]
end function
item = getSomething("nonExistingId")
print item ' prints "invalid"
print item.name ' CRASH!
function ensureSomething(id as String) as ISomething
' This function always returns something, so there's no need to specify "or invalid" in
' the return type. And the user knows they don't need to check for invalid values
' either.
item = m.myMapOfThings[id]
if item = invalid
item as Something = {
id: id
name: ""
value: -1
}
m.myMapOfThings[id] = item
end if
return item
end function
item = ensureSomething("nonExistingId")
print item ' prints "<roAssociativeArray>"
print item.name ' prints ""Metadata
Metadata
Assignees
Labels
No labels