Skip to content
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

Can't directly construct a generic list from a Boolean scalar #17731

Open
iRon7 opened this issue Jul 20, 2022 · 3 comments
Open

Can't directly construct a generic list from a Boolean scalar #17731

iRon7 opened this issue Jul 20, 2022 · 3 comments
Assignees
Labels
Issue-Bug Issue has been identified as a bug in the product Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Engine core PowerShell engine, interpreter, and runtime

Comments

@iRon7
Copy link

iRon7 commented Jul 20, 2022

Steps to reproduce

These statements return an error:

[System.Collections.Generic.List[bool]]$False
[System.Collections.Generic.List[bool]]$True
[System.Collections.Generic.List[psobject]]$True
[System.Collections.Generic.List[bool]]($True)

$Bool = $True
[System.Collections.Generic.List[bool]]$Bool

While these statements work fine:

[System.Collections.Generic.List[int]]3
[System.Collections.Generic.List[string]]'Test'
[System.Collections.Generic.List[psobject]]'Test'
[System.Collections.Generic.List[bool]]($True, $True)
[Array]$True

Expected behavior

All statements to return a generic list with a single (boolean) item without any error

Actual behavior

Statements that have a single boolean as constructor parameter produce an error

Error details

InvalidArgument: Cannot convert value "True" to type "System.Collections.Generic.List`1[System.Boolean]". Error: "Invalid cast from 'System.Boolean' to 'System.Collections.Generic.List`1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'."

Workaround:

Use the Array subexpression operator @( ):

[System.Collections.Generic.List[bool]]@($True)
$True

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@iRon7 iRon7 added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jul 20, 2022
@iRon7 iRon7 changed the title Can't directly construct a generic Boolean list from a Boolean scalar Can't directly construct a generic list from a Boolean scalar Jul 21, 2022
@daxian-dbw daxian-dbw added the WG-Engine core PowerShell engine, interpreter, and runtime label Jul 21, 2022
@SeeminglyScience SeeminglyScience added the Issue-Bug Issue has been identified as a bug in the product label Sep 19, 2022
@vexx32
Copy link
Collaborator

vexx32 commented Sep 19, 2022

Discussed this today with the Engine Working Group.

Definitely looks like a bug to us, we agree this should be fixed. Given the impact is fairly low and the workaround pretty trivial, this is a low priority for the team to handle directly. Marking it as up for grabs for now.

Thanks for reporting this one! 💖

@vexx32 vexx32 added Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Sep 19, 2022
@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 15, 2023
@iRon7
Copy link
Author

iRon7 commented Nov 15, 2023

The Issue-Bug still exists:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.9
PSEdition                      Core
GitCommitId                    7.3.9
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@iRon7
Copy link
Author

iRon7 commented May 14, 2024

This bug was already qualified for Up-for-Grabs and still exist on PowerShell version: 7.4.2

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

4 participants