rokucommunity / rokucommunity/brighterscript

Enum transpilation bug

Open
#1,507 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug transpiler
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.

CompilationErrorPOCApp.zip

BrighterScript version 0.69.0

Originally reported in this slack convo.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.