Skip to content

Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects that are implicitly treated as collections #6456

@mklement0

Description

@mklement0

[Superseded by #6466]

#3671 discussed the issue with respect to [pscustomobject] instances, for which a fix was attempted in #5756 (but the fix is not in v6.0.2 - @iSazonov, should it be?).

However, there are instances of other types where the problem persists.

It would be good to clarity on the generic issue, so that it can be fixed for any (current and future) type.

Steps to reproduce

([System.Data.DataTable]::new()).Count
([pscustomobject] @{}).Count

Expected behavior

0   # because [System.Data.DataTable] is treated as an *enumerable* - see @stknohg's comment below.
1

Actual behavior

The output is $null, because there is no .Count property.

Environment data

PowerShell Core v6.0.2 on macOS 10.13.3
PowerShell Core v6.0.2 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.2 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 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 reclassifResolution-AnsweredThe question is answered.WG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions