Skip to content

[enum] Without Flags Inconsistent Behavior And Implicit Casting #21

@mattcargile

Description

@mattcargile

I found this trap while passing an @() to a [enum] parameter without the Flags attribute. This occurs on 5.1.22621.4391 and 7.4.6.

The simplest demo is below just with the [type].

[DayOfWeek]'Monday,Tuesday'
# Returns Wednesday
[DayOfWeek]@('Monday','Tuesday')
# Returns Wednesday

In a [scriptblock] or function{}, it is a bit more problematic as I would expect it to throw and the implicit cast returns inconsistent results.

& {
    param( [DayOfWeek]$d )
    $d -eq 'Wednesday'
} Monday,Tuesday
# Returns Wednesday

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions