By definition, using attribute ValueFromRemainingArguments on a parameter:
Both At least the former condition should be enforced at parse time, because functions that violate these principles fail on invocation in the typical use case.
[As noted below, the must-be-unconstrained-or-array condition cannot be reliably enforced without preventing exotic, but legitimate use cases.]
Steps to reproduce
Define the following functions:
# Define *multiple* `ValueFromRemainingArguments` parameters, which makes no sense.
function Foo1 {
[CmdletBinding()]
param(
[Parameter(ValueFromRemainingArguments)]
$Rest1,
[Parameter(ValueFromRemainingArguments)]
$Rest2
)
'hi1'
}
# Define a `ValueFromRemainingArguments` parameter with a *scalar type*, which
# generally makes no sense, because the whole idea behind the attribute is to collect
# *multiple* arguments.
function Foo2 {
[CmdletBinding()]
param(
[Parameter(ValueFromRemainingArguments)]
[int] $Rest
)
}
Then, assuming you can define them (which you shouldn't be able to), invoke them:
Expected behavior
Parsing the function definitions should fail, because they violate the idea behind the ValueFromRemainingArguments attribute.
Actual behavior
# Foo1 was successfully defined, but cannot be invoked with positional arguments.
Foo1 : Parameter set cannot be resolved using the specified named parameters.
# Foo2 was successfully defined, but fails with more than 1 [int] argument.
Foo2 : Cannot process argument transformation on parameter 'Rest'. Cannot convert the "System.Collections.Generic.List`1[System.Object]" value of type
"System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]" to type "System.Int32".
In fact, Foo2 even fails with a single [int] argument, because a ValueFromRemainingArguments parameter currently unconditionally returns a [List[object]] instance, even if only a single argument is bound - see #4625
Environment data
PowerShell Core v6.0.0-beta.5 on macOS 10.12.6
PowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
By definition, using attribute
ValueFromRemainingArgumentson a parameter:only makes sense on one parameter
which should either be unconstrained, or declared as an array.
BothAt least the former condition should be enforced at parse time, because functions that violate these principles fail on invocation in the typical use case.[As noted below, the must-be-unconstrained-or-array condition cannot be reliably enforced without preventing exotic, but legitimate use cases.]
Steps to reproduce
Define the following functions:
Then, assuming you can define them (which you shouldn't be able to), invoke them:
Expected behavior
Parsing the function definitions should fail, because they violate the idea behind the
ValueFromRemainingArgumentsattribute.Actual behavior
In fact,
Foo2even fails with a single[int]argument, because aValueFromRemainingArgumentsparameter currently unconditionally returns a[List[object]]instance, even if only a single argument is bound - see #4625Environment data