Skip to content

A "hybrid" bareword command argument that is parsed as a number unexpectedly behaves like a string with -f (format operator) #17199

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

Passing a bareword argument to a parameter that isn't type-constrained is parsed as a number if it looks like one.

The resulting value self-identifies as a number and mostly acts as such, but it is wrapped in an invisible [psobject] instance in which the original string representation is cached.

In the context of -f, this string representation surfaces unexpectedly, meaning that the value is unexpectedly not treated as a number:

& { param($p) $p.GetType().FullName; '{0:N2}' -f $p } 0x1a

Expected behavior

System.Int32
26.00

Actual behavior

System.Int32
0x1a

Error details

No response

Environment data

PowerShell Core 7.3.0-preview.3

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions