Skip to content

A ValueFromRemainingArguments parameter by default invariably receives a [List[object]] collection rather than a scalar / PowerShell array ([object[]]), as appropriate #4625

@mklement0

Description

@mklement0

Related: #3773 and #3154

Declaring a (at most 1) parameter with attribute ValueFromRemainingArguments allows you to collect any remaining arguments - those not bound to other parameters - in a single parameter.

Given that there may be 1 or more remaining arguments, that would usually imply:

  • bind a scalar to the parameter if there's only one remaining argument
  • bind a regular PowerShell array ([object[]]), if there are multiple remaining arguments.

By contrast, a [List[object]] instance is currently bound, irrespective of whether 1 or more remaining arguments are bound.

Steps to reproduce

Create script t.ps1 in the current dir. with the following content:

[CmdletBinding()]
param(
  [Parameter(ValueFromRemainingArguments)]
  $Rest
)
$Rest.Count
$Rest.GetType().FullName

Then call:

./t foo
./t foo bar

Expected behavior

1
System.String
2
System.Object[]

Actual behavior

1
System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
2
System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions