-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fixes #11606 - Add information about numeric parameter names #11623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
PR Summary
Add information about numeric parameter names
PR Checklist