rokucommunity / rokucommunity/brighterscript

Null Coalescing expressions should handle `<uninitialized>`

Open
#1,543 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
208
Forks
68
Avg merge
8h 39m
Merged PRs (30d)
39

Description

Proposal

Enhance the null coalescing operator to also check for <uninitialized>. Either invalid or <uninitialized> will result in the alternate being selected. Example:

thing = notDefined
result = thing ?? "default"

Will now transpile to:

thing = notDefined
result = thing
if type(thing) = "<uninitialized>" or thing = invalid
    result = "default"
end if

Justification:

Developer intent for null coalescing is to pick an alternate value if the consequent value is not defined. invalid and <uninitialized> both represent this concept of "not defined", and as such, we can produce safer code while maintaining the intent behind null coalescing.

Example:

thing = notDefined
result = thing ?? "default"

In the current releases of BrighterScript, this throws an exception when comparing thing (which is <uninitialized>) to invalid

Image

Questions:

  • should this be considered a breaking change or a bugfix? (i.e. should this only be added to v1, or can we also add to v0)

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

Read docs/null-coalescing-operator.md and reproduce the issue's ?? example with an uninitialized value. Trace the null-coalescing transpilation entry point, then verify that both invalid and <uninitialized> select the alternate without an exception; the issue also leaves the v0 versus v1 decision open.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.