rokucommunity / brighterscript

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

Adds `typecast m as <Type>` statement #1140

Closed markwpearce closed 4 months ago

markwpearce commented 4 months ago

Adds ability to add a single statement to beginning of file or function, and every usage of m in that or lower scopes will be typecast as the type given.

Syntax:

typecast m as <type>

eg:

import "types.bs"
typecast m as Thing1

sub func1()
    x = m.value ' x is type of Thing1.value
    print x
end sub

sub func2()
    typecast m as Thing2 
    x = m.value  ' x is type of Thing2.value
    print x
end sub

sub func3()
    aa = {
        innerFunc: sub()
            typecast m as Thing3
            x = m.value  ' x is type of Thing3.value
            print x
        end sub
    }
end sub

class TestKlass
    value as string

    sub method1()
        x = m.value ' x is type of TestKlass.value
        print x
    end sub

    sub method2()
        typecast m as Thing1
        x = m.value  ' x is type of Thing1.value
        print x
    end sub
end class
markwpearce commented 4 months ago

addresses: #1036