You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
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
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
#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 - Ilya (@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.
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)
changed the title [-]Treating scalars implicitly as collections doesn't with all objects - some lack a .Count property[/-][+]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property[/+]on Mar 22, 2018
changed the title [-]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property[/-][+]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects treated implicitly as collections[/+]on Mar 22, 2018
changed the title [-]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects treated implicitly as collections[/-][+]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects that are treated implicitly as collections[/+]on Mar 22, 2018
changed the title [-]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects that are treated implicitly as collections[/-][+]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[/+]on Mar 22, 2018
Ilya (@iSazonov): Thanks; your [pscustomobject] fixes were indeed effective in all respects (.Count, [0], .ForEach(), .Where()), I checked with the latest code. The issue with [DataTable] is a different one that I'll address in a new issue.
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
Activity
[-]Treating scalars implicitly as collections doesn't with all objects - some lack a .Count property[/-][+]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property[/+]stknohg commentedon Mar 22, 2018
DataTableis defined as enumerable in PowerShell.I think
([System.Data.DataTable]::new()).Countshould retruns
0.but this expression returns nothing currently...
I think it is a bug.
workaround?
([System.Data.DataTable]::new().Rows).Countreturns
0as expected.mklement0 commentedon Mar 22, 2018
Takuya Shibata (@stknohg): Thanks, good point about
[System.Data.DataTable]being enumerable (though seemingly not in all contexts (anymore) - I've updated the original post.Yes, it should return
0in this case (or, generally, however many rows the.Rowsproperty contains) which, as you state, doesn't work.[-]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property[/-][+]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects treated implicitly as collections[/+][-]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects treated implicitly as collections[/-][+]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects that are treated implicitly as collections[/+][-]Treating scalars implicitly as collections doesn't work with all objects - some lack a .Count property, as do some objects that are treated implicitly as collections[/-][+]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[/+]iSazonov commentedon Mar 22, 2018
v6.0.2 is only security update.
iSazonov commentedon Mar 22, 2018
Is the Issue for
ForEachandWheretoo?mklement0 commentedon Mar 22, 2018
Ilya (@iSazonov): Thanks; your
[pscustomobject]fixes were indeed effective in all respects (.Count,[0],.ForEach(),.Where()), I checked with the latest code. The issue with[DataTable]is a different one that I'll address in a new issue.