rokucommunity / rokucommunity/brighterscript
ternary op behaves incorrectly with arrays in the operands
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 208
- Forks
- 68
- Avg merge
- 8h 39m
- Merged PRs (30d)
- 39
Description
(using rooibos w/brighterscript)
I don't expect this to crash (and it rightly doesn't crash): result = type("") = "Integer" ? [1][""] : "0"
because I don't expect the operand that handles the truthy flow to be evaluated when the first condition is false
however, this does crash: m.assertEqual(type("") = "Integer" ? [1][""] : "0", "0")
it seems like when the ternary op is included as an argument in this assert, the truthy operand gets evaluated even though the condition is false
note that I've seen the ternary op similarly transpiled when used as the operand of the return statement
also notable that transpiling seems to handle things differently when at least one of the operands has an array in it - basically it is transpiled to a function call vs. getting transpiled to an if-then statement (I think this results in all operands getting evaluated instead of just those that should be)
side note: thinking out loud here... I would guess that in this case where the result of the transpiler is a function call, that each argument of the function gets evaluated in order from left to right (which would more or less match the general order we expect ternary ops to be evaluated in - excepting the path that should get skipped). If this ordering is not guaranteed, I wonder how that would impact ternary...
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 by reproducing the ternary examples in rooibos with BrighterScript, including assignment, m.assertEqual, and return, then compare the transpiled output when arrays are operands. The fix is complete when the false branch is not evaluated in each context and the examples no longer crash.
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
- 35/100