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
Fix the parsing code for method generic arguments #16937
Conversation
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.
LGTM!
This looks good to me overall! I would ask that we add a test similar to this actual use case from the linked issue: [IPAddress]::Parse(
$_.IPSubnet[
([Array]::IndexOf($_.IPAddress, $_.IPAddress[0]))
]
) It's a bit of an odd case but does look like a pretty solid test case where we should be recognising the index expression instead of a partial generic method syntax. |
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.
LGTM
It indeed looks a bit odd but it's just a simplified version of following code that selects IP subnet from IP subnets array based on IP address index in corresponding IP address array: ...
$IPAddress = $_.IPAddress | Where-Object {$_ -like $using:Filter} | Select-Object -First 1
$IPSubnet = [IPAddress]::Parse(($_.IPSubnet[[Array]::IndexOf($_.IPAddress, $IPAddress)]))
... |
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
The |
🎉 Handy links: |
PR Summary
Fix #16870
Update the parsing code to only support the syntax
$var.Method[TypeName1 <, TypeName2 ...>]
for method generic arguments, not the syntax$var.Method[[TypeName1] <, [TypeName2] ...>]
.The latter syntax has been supported for type expression since the beginning, but it's ambiguous in this scenario because we could be looking at an indexing operation on a property like:
$var.Property[<expression>]
and the<expression>
could start with a type expression like[TypeName]::Method()
, or even just a single type expression acting as a key to a hashtable property. Such cases will cause ambiguities.Even though it might be possible to write code that sorts out the ambiguity and continue to support the latter syntax for method generic arguments, I choose not to do so, because:
The downside is that the assembly-qualified type names won't be supported for method generic arguments, but that's likely not a problem in practice, and we can revisit if it turns out otherwise.
Besides, there is no point to allow declaring generic arguments for a property. Even for method group, it makes no sense to allow generic arguments to be declared for it because we don't do anything with the generic arguments for a method group, so no validation will be done -- you will see the following script works in 7.3-preview.1 unexpectedly:
So, the related code in AST and parser are removed, and declaring a generic argument on a property will generate the same parsing errors as before:
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.