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
The first array type in a generic method doesn't work #18686
Comments
It should work like this: [Linq.Enumerable]::SelectMany(
[int[][]] @((,2), (,4), (,6), (,8)),
[Func[[int[]], int[]]] { param ($x); $x }
) | ConvertTo-Json -Compress Great reference for Linq in Powershell: |
It looks like the list of the generic-method type arguments isn't recognized as such and instead (mis)interpreted as a type literal, and the problem seemingly only occurs when the first type in such a list is an array type ( A simpler repro (note that the call doesn't make sense, but the error message reveals wether type arguments where formally parsed as such): # !! -> "InvalidOperation: Unable to find type [int,int]."
[char]::ToUpper[int[], int]()
# !! Using the list as a (broken) type literal yields the same error.
[int[], int]
# (Formally) OK; -> "Could not find a suitable generic method overload for ..."
[char]::ToUpper[int, int[]]() |
I believe this is an existing problem with generic types that has just been made more common. I don't think I ever filed an issue, but I've hit this quite a few times with delegate types: # Also throws
[Func[int[], int]] Fortunately the work around is really easy for generic types, just surround the inner type in more square brackets: [Func[[int[]], int]] Unfortunately, this doesn't work with generic method args: # Throws differently because we don't seem to be checking for brackets around generic args
[Linq.Enumerable]::SelectMany[[int[]], int](
[int[][]] @((,2), (,4), (,6), (,8)),
[Func[[int[]], int[]]] { param ($x); $x }
) | ConvertTo-Json -Compress |
/cc @daxian-dbw @vexx32 FYI |
The latter you mention (double-bracketing) I think was at least semi-intentional, since The initial issue here seems to be... hm. Not a parsing error directly perhaps, but definitely something strange. This code path parser-wise at least is very messy due to the overloaded meaning for |
Rob has reported it here: #9639 |
I even already gave it a thumb! Good catch, thanks @MartinGC94! |
🎉This issue was addressed in #19205, which has now been successfully released as Handy links: |
Prerequisites
Steps to reproduce
When I try to flatten a two-dimensional array by
Enumerable.SelectMany
method with generic type arguments, the first type argumentint[]
may not be treated correctly.Expected behavior
[2,4,6,8]
Actual behavior
Unable to find type [int,int].
Error details
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: