rokucommunity / brighterscript

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

feature request: case SENSITIVE object literals #723

Open ZeeD opened 1 year ago

ZeeD commented 1 year ago

according to https://developer.roku.com/en-gb/docs/references/brightscript/language/expressions-variables-types.md

[...] an AssociativeArray literal like this will also create the entry in lower case: aa = { NewKey: 55 } To create mixed case keys, use the array operator or the ifAssociativeArray.AddReplace method: aa["NewKey"] = 55

this means that when I wrote

foo = { aKey: "aValue" }
print(foo.keys()[0] = "aKey")

will print false

this behavior is... "unusual", IMHO, and I would like to have bsc to treat object literals in a way to force case sensitivity. for example, the expression foo = { aKey: "aValue" } in .bs could be converted in something like

foo = {}
foo["aKey"] = "aValue"
foo.setModeCaseSensitive() ' this is just an additional enforcement on what I think is a "sane" behavior
TwitchBronBron commented 1 year ago

That's an interesting proposal. I'm wondering how to handle AAs created from external libraries. Like, consider this code:

' this AA is not under our control, so how do we handle it? 
' We probably shouldn't set it to case sensitive for fear of breaking their internal code
someAA = someExternalLib_CreateSomething()
ZeeD commented 1 year ago

I'm wondering how to handle AAs created from external libraries.

uhm, in my mind it's a bit too invasive, and not really useful please correct me if I'm wrong, but external libraries are already distributed as "normal" brightscript files - because written directly in, or compiled from brighterscript to, during the packaging process.

Changing the internals of someExternalLib_CreateSomething, while may produce a more "uniform" behavior for all the project, will also break the library itself, so it's really not worth it.

I think it would be more useful (and maybe easier to obtain?) to just focus on the .bs to .brs compilation phase. This means that "some" objects are case sensitive and some not, but it's something that any roku developer should know - as that .setModeCaseSensitive can change the behavior per object, not globally