rokucommunity / rokucommunity/brighterscript

Null-coalescing transpilation can cause problems in print statements

Open
#1,194 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Consider:

  print "Values:" data.values ?? []

transpiles to:

    print "Values:" (function(data)
            __bsConsequent = data.values
            if __bsConsequent <> invalid then
                return __bsConsequent
            else
                return []
            end if
        end function)(data)

this transpilation causes a run-time error:
Function Call Operator ( ) attempted on non-function. (runtime error &he0)

however, if it is preceded with a semi-colon, then it does not have any problem.

  print "Values:"; data.values ?? []

gives:

   print "Values:"; (function(data)
            __bsConsequent = data.values
            if __bsConsequent <> invalid then
                return __bsConsequent
            else
                return []
            end if
        end function)(data)

If any self-invoking function in transpilation (eg. null-coalescing, ternary, etc.) is in a print statement.. it's probably best to precede it with a semi-colon.

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 by reproducing the issue with the provided BrightScript print statement and inspect the transpilation path for null-coalescing and other self-invoking expressions inside print statements. Done means the example runs without the Function Call Operator runtime error while preserving the intended print behavior, including both separator forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.