Skip to content

v5 Regression: Casting object[] to more narrow generic collection fails with a single element, but not with two #2208

@oising

Description

@oising

Steps to reproduce

> [Collections.Generic.List[int]]@(1)

or

> [Management.Automation.LanguagePrimitives]::ConvertTo(@(1), [Collections.Generic.List[int]])

Note that casting @(1,2) will succeed. Only the case @(1) fails. This is a regression because it functions correctly in v4.

Expected behavior

Casts to an instance of List<int> containing a single element: 1

Actual behavior

Exception calling "ConvertTo" with "2" argument(s): "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Int32"."

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.10586.494
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.494
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productWG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions