Skip to content

It should be possible to discover (print) the overloads of the intrinsic ForEach and Where array methods #14376

Closed

Description

Invoking a method type member without (...) outputs System.Management.Automation.PSMethod`1 instances describing the method's signatures (overloads), which is helpful in interactive discovery; e.g.:

PS> 'foo'.ToString

OverloadDefinitions
-------------------
string ToString()
string ToString(System.IFormatProvider provider)
string IConvertible.ToString(System.IFormatProvider provider)

However, this doesn't currently work for the intrinsic .ForEach() and .Where() array methods implicitly available on all objects (though tab-completion does recognize them); e.g., (1, 2).ForEach returns $null

(As a side effect, with Set-StrictMode -Version 2 or higher, (1, 2).ForEach fails outright; conceptually related: #2798)

Steps to reproduce

(1, 2).ForEach | Should -Not -BeNullOrEmpty
(1, 2).Where | Should -Not -BeNullOrEmpty

Expected behavior

Both tests should pass.

Actual behavior

Both tests fails, because both expressions evaluate to $null instead of outputting System.Management.Automation.PSMethod`1 instances.

Environment data

PowerShell Core 7.2.0-preview.1

Activity

  1. added
    Issue-Question
    on Dec 10, 2020
  2. added
    Issue-Enhancement
    WG-Engine
    and removed
    Issue-Question
    on Dec 12, 2020
  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. added
    Resolution-No Activity
    on Nov 16, 2023
  5. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions