Skip to content

Allow to statically analyze messages to detect undefined local variables #403

Closed
@stasm

Description

@stasm

This is a follow-up to a conversation I had with @mihnita about variable shadowing. See #310 and #402 for context. I think we've been focusing too much on whether local variables should be allowed to shadow other local variables, and that we treated the question of local variables' shadowing of the message argument as derivative. I'm here to argue that we should reverse this and first discuss whether local variables are allowed to shadow message arguments.

Mihai observed that in the current design in which local variables share the namespace with message arguments it's impossible to statically analyze references to local variables. In the following message we can't with certainty detect that $fooo is a typo, because it could be a message argument (i.e. a value provided by the developer of the app at the callsite of the MF API).

let $foo = {1}
{Hello, {$fooo} and {$user}.}

Forbidding such redefinitions is difficult pre-runtime, because the list of message arguments is unknown upfront.


One idea could be to provide a way for message authors to define message argument names in the message itself, for example:

input $user
let $foo = {1}
{Hello, {$fooo} and {$user}.}

Another solution would be to redefine the syntax for local variables such that it prevents name conflicts with message arguments. This could be done through a new sigil (@mihnita suggested #foo) or through an extra requirement to the name, e.g. a dash in the middle of the name: $my-foo, similar to how HTML allows custom element names.


Do others also feel that not being able to do extensive static analysis on variable names is a problem that needs to be fixed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleObsolete?resolve-candidateThis issue appears to have been answered or resolved, and may be closed soon.syntaxIssues related with syntax or ABNF

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions