Skip to content

Function parameter is overridden by a same-named global variable #582

Description

@logbie

Summary

When a function (action) parameter has the same name as an existing global variable, calls to that action ignore the passed argument and use the global's value instead. Parameters should shadow globals, not be overwritten by them.

Minimal reproduction

define action called takes_p with parameters p:
    return p
end action

store p as "GLOBAL-VALUE"
display "expected 'arg', got: " with takes_p of "arg"

Actual output:

expected 'arg', got: GLOBAL-VALUE

Expected output:

expected 'arg', got: arg

By contrast, an action-local variable (store loc as ...) correctly shadows a same-named global — only parameters are affected.

Impact

This is a silent correctness bug. Any library that defines actions with common parameter names (t, s, v, i, name, value, node, …) will misbehave the moment a caller happens to have a global of the same name — with no error, just wrong results.

I hit this building a templating engine in WFL: internal helpers with parameters named t/v were silently overwritten whenever the calling program had globals of those names, corrupting every result. The workaround was to prefix every parameter with a rare marker (sc_), which shouldn't be necessary.

Environment

  • wfl built from source at current main
  • rustc 1.94.1, cargo 1.94.1, Linux

Suggested fix

Parameter bindings should be introduced into the action's own local scope and take precedence over globals during name resolution inside the action body.

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