rokucommunity / brighterscript

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

cannot have a constructor parameter with the same name of the class #661

Closed ZeeD closed 2 years ago

ZeeD commented 2 years ago

snippet:

class Name
    sub new(name)
    end sub
end class

bsc returns this error: error BS1106: Local variable has same name as class 'Name'

(using brighterscript 0.55.1)

TwitchBronBron commented 2 years ago

Unfortunately, this is actually by design. This is functionally no different than doing:

function name(name)
    ' which variable are you referencing? Depending on the thread and sg version and whether you've shown the scene yet, it could be either the local var OR the function
    print name 
end function

Until we add some type of case-sensitive transpile mode, variables cannot have the same name as any classes/interfaces/namespaces/functions/enums/consts .

ZeeD commented 2 years ago

Oh. OK.

FWIW: more than case-sensitivity I was hoping that bsc could transparently add some name mangling (fox example adding some prefixes/suffixes) to disambiguate these scenarios, but I can add them myself in this specific case.

TwitchBronBron commented 2 years ago

Oh. OK.

FWIW: more than case-sensitivity I was hoping that bsc could transparently add some name mangling (fox example adding some prefixes/suffixes) to disambiguate these scenarios, but I can add them myself in this specific case.

I would love to see BrighterScript support this type of functionality in the future! If you're interested, we'd gladly welcome a PR that adds this functionality.