rokucommunity / rokucommunity/brighterscript
Null Coalescing expressions should handle `<uninitialized>`
Nobody has claimed this yet.
- 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
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
- 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
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