rokucommunity / brighterscript

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

`CreateObject` function call implies correct return type #1154

Closed markwpearce closed 2 months ago

markwpearce commented 2 months ago

Previously, everything returned from createObject was ObjectType

Now, it looks at the arguments, and if passed string literals, it is able to infer either the built-in Component/Object or a custom component:

dateTime = createObject("roDatetime") ' this is the InterfaceType `roDateTime`
dateTime.getHours() ' this is an integer

button = createObject("roSgnode", "Poster") '  this is the ComponentType `roSgNodePoster`
button.uri ' this is a string

if the args are not string literals, it still just returns ObjectType....

function getObject(objectName as string)
    return createObject(objectName) ' this is just ObjectType
end function
markwpearce commented 2 months ago

Ok. Hmmm. I don’t know about making support for overloading functions yet, so maybe I’ll change this so it’s just a special case, and does not change the interface/constructors for anything yet.