-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Languageparser, language semanticsparser, language semantics
Description
Please provide ability to invoke generic methods with explicit type parameters.
Steps to demonstrate
[Array]::Empty[string]()or using a class:
class A {
static [string] GetTypeName[T]() { return [T].Name }
}
[A]::GetTypeName[string]()(Array.Empty was chosen as a simplest possible example. In scripts Iʼd use @())
Current behavior
At line:1 char:16
+ [Array]::Empty[string]()
+ ~
Array index expression is missing or not valid.
At line:1 char:16
+ [Array]::Empty[string]()
+ ~~~~~~~
Unexpected token 'string]' in expression or statement.
At line:1 char:24
+ [Array]::Empty[string]()
+ ~
An expression was expected after '('.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArrayIndexExpression
Ruminations
I understand that itʼs not important to have full support of generics in a scripting language or to have 100% feature parity with C# (I might be wrong, — now we have classes in PowerShell after all 🤔)
Here are some not-very-elegant workarounds from the Interwebs:
- Workaround to call to a generic method OfType() in PowerShell, when PowerShell cannot figure out from the context by @vors
- PSGenericMethods module by @dlwyatt
- Invoking Generic Methods on Non-Generic Classes in PowerShell by @LeeHolmes
- How do I call a parameterless generic method from Powershell v3?
Here are my questions:
- Is it possible to implement this at all? How hard it could be?
- Anyone tried to implement this before?
- Is it worthwhile?
Just posting this here for discussion. Didnʼt find any mentions of this problem in other issues.
fMichaleczek, LaurentDardenne, Jaykul, bergmeister, HarinezumiSama and 21 more
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Languageparser, language semanticsparser, language semantics