Skip to content

Set-StrictMode should detect use of automatic variables as parameters or the target of an assignment #3061

@briantist

Description

@briantist

It's common for people to inadvertently to use an automatic variable as a parameter name or a variable name, and then get confused when it doesn't contain the value they expect.

This is just one example but it comes up fairly often, and unless you already know the name is reserved, PowerShell doesn't offer you any clues as to what's going on.

Because the various automatic variables get overwritten based on different conditions, it can be even more confusing when it seems to work in one context but not another.

Given Set-StrictMode's other roles, this seems like a good fit.

One intentional use is for nullification, as in:

$null = Invoke-CommandWithUnwantedOutput

So that could be an exception (because it's unlikely to be done unintentionally), but my thoughts are that there are other ways to achieve this, and strict mode is not enabled by default, so in my opinion it should not be an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions