rokucommunity / rokucommunity/brighterscript
Enum transpilation bug
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 208
- Forks
- 68
- Avg merge
- 8h 39m
- Merged PRs (30d)
- 39
Description
There's something strange about using enums. A single file defines an enum, and then a const uses that enum:
enum AdEventTypes
adbegin = "adbegin"
end enum
const AdEventMap = {
adbegin: AdEventTypes.adbegin
}
When using AdEventMap in the app, it crashes with an error: 'Dot' Operator attempted with invalid BrightScript Component or interface reference. If using a string literal for the value on AdEventMap, it works fine. Furthermore, if the object is defined in a function instead of directly on the const, it works fine:
function generateAdEventMap() as object
eventMap = {
adbegin: AdEventTypes.adbegin
}
return eventMap
end function
const AdEventMap = generateAdEventMap()
Is this a bug or am I using it wrong? I thought the enums all got replaced with string literals during compilation. Does that not apply to consts?
Here's a simple reproducible project.
BrighterScript version 0.69.0
Originally reported in this slack convo.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached CompilationErrorPOCApp.zip and reproduce the failure using BrighterScript 0.69.0. Trace how enum references are transpiled inside a top-level const initializer, then add a regression test showing that AdEventMap works like the function-created map without producing the invalid Dot error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100