Skip to content

Conversation

sdwheeler
Copy link
Collaborator

@sdwheeler sdwheeler commented Jan 2, 2025

PR Summary

Add information about numeric parameter names

PR Checklist

  • Descriptive Title: This PR's title is a synopsis of the changes it proposes.
  • Summary: This PR's summary describes the scope and intent of the change.
  • Contributor's Guide: I have read the contributors guide.
  • Style: This PR adheres to the style guide.

Copy link
Contributor

Learn Build status updates of commit 73dad68:

✅ Validation status: passed

File Status Preview URL Details
reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md ✅Succeeded View (powershell-5.1)
reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced.md ✅Succeeded View (powershell-5.1)
reference/5.1/Microsoft.PowerShell.Core/About/about_Variables.md ✅Succeeded View (powershell-5.1)
reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md ✅Succeeded View (powershell-7.4)
reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced.md ✅Succeeded View (powershell-7.4)
reference/7.4/Microsoft.PowerShell.Core/About/about_Variables.md ✅Succeeded View (powershell-7.4)
reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md ✅Succeeded View (powershell-7.5)
reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced.md ✅Succeeded View (powershell-7.5)
reference/7.5/Microsoft.PowerShell.Core/About/about_Variables.md ✅Succeeded View (powershell-7.5)

For more details, please refer to the build report.

For any questions, please:

@sdwheeler sdwheeler merged commit 1b73296 into MicrosoftDocs:main Jan 2, 2025
6 checks passed
@sdwheeler sdwheeler deleted the sdw-w359338-i11606 branch January 3, 2025 17:43
@surfingoldelephant
Copy link
Contributor

surfingoldelephant commented Jan 4, 2025

Thanks for tackling this (and my other recent issues), @sdwheeler.

I've left a couple of comments on points I feel need addressing.

> [!IMPORTANT]
> It's possible to name a parameter using only decimal digits. Using numeric
> parameter names isn't recommended because it can lead to confusion with
> positional parameters.
Copy link
Contributor

@surfingoldelephant surfingoldelephant Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is not limited to digit-only parameter names. The issue applies to parameter names that start with a digit, irrespective of the characters that follow.

For example, the following is just as susceptible to the raised issue, despite it not using only decimal digits/being numeric.

function TestFunction { param ([string] $1Foo) "1Foo: $1Foo" }
TestFunction -1Foo Bar

# Broken:
# 1Foo: -1Foo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I missed that distinction. I will update the docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

```

If you try to use the parameters, PowerShell interprets them as negative
numbers passed as positional parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate. The token is parsed as a string - see the AST output in the original example.

To demonstrate this in practice:

function TestFunction { param ([object] $100) $100.GetType().Name }
TestFunction -100 # String

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add warning to avoid naming a parameter beginning with a number

2 participants