Skip to content

Null coalescing operator used with namespace constant results in warning #1545

@borcic

Description

@borcic

A pattern we have been using is to retrieve a value from a remote configuration, but fallback to a local constant if the remote value isn't defined.
For example:

url = m.config?.serviceUrls?.imageService ?? CommonConfigConst.imageServiceUrl

where CommonConfigConst.imageServiceUrl is defined as

namespace CommonConfigConst
    const imageServiceUrl = "https://<some server>/"
end namespace

The transpiler converts that to

url = (function(CommonConfigConst, m)
                __bsConsequent = m.config?.serviceUrls?.imageService
                if __bsConsequent <> invalid then
                    return __bsConsequent
                else
                    return "https://i<some server>/"
                end if
            end function)(CommonConfigConst, m)

When the channel is side loaded, we see a warning in the console:

BRIGHTSCRIPT: WARNING: unused variable 'commonconfigconst' in anonymous function in /<path to code>/ImageService.bs:62

It seems that the transpiler is inlining the constant, but treating the namespace as a variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions