Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null-coalescing transpilation can cause problems in print statements #1194

Open
markwpearce opened this issue May 17, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@markwpearce
Copy link
Collaborator

markwpearce commented May 17, 2024

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.

@markwpearce markwpearce added the bug Something isn't working label May 17, 2024
@markwpearce
Copy link
Collaborator Author

Alternately, we could just ALWAYS insert a semicolon between parts of a print statement... I don't think that would hurt anything.

@markwpearce markwpearce changed the title Null-coalescing transpilation causes problems in some situations. Null-coalescing transpilation can cause problems in print statements May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant