sjbarag / brs

An interpreter for the BrightScript language that runs on non-Roku platforms.
MIT License
113 stars 43 forks source link

Having a 'return' statement on a sub that is called by an onChange event is raising an error: #503

Closed adheus closed 4 years ago

adheus commented 4 years ago

Given the following node: SomeNode.xml

<component name="SomeNode" extends="Group">
    <interface>
        <field id="someText" type="string" onChange="onSomeTextChanged" />
    </interface>
    <script type="text/brightscript" uri="SomeNode.brs" />
</component>

SomeNode.brs

sub init()
    ?"Initing SomeNode..."
    onSomeTextChanged({fakeEvent: ""})
end sub

sub onSomeTextChanged(event=invalid)
    ?"onSomeTextChanged called"
    if event <> invalid
        ?"Event is not invalid"
        return
    end if
end sub

When executing the following steps on main.brs:

node = CreateObject("roSGNode", "SomeNode")
node.someText = "some"

We have the following output:

Initing SomeNode... onSomeTextChanged called Event is not invalid onSomeTextChanged called Event is not invalid source/main.brs(3,7-15): return encountered

Notice that the first call to onSomeTextChanged(outside of the onChange scope) does not raise an error but the onChange one does.

vbuchii commented 4 years ago

I was going to fill out the ticket about it but it is already here :)

sjbarag commented 4 years ago

Fixed as part of #522 (which I incorrectly attributed to #508, I'm sorry!) — should be included in our next release 😃