Skip to content

enum: Underlying type #8028

@indented-automation

Description

@indented-automation

Enumerations in PowerShell appear to be limited to Int32. Ideally enums should allow inheritance-style setting of the underlying type.

Steps to reproduce

PowerShell does not appear to allow an underlying type to be defined for an enum. All values are coerced to Int32.

The statement below will raise an exception:

enum Fruit { Apple = 0x0FFFFFFFFFFFFFFF }

Expected behavior

An enumeration wiith underlying type set to [Int64] to be created.

enum Fruit { Apple = 0x0FFFFFFFFFFFFFFF }
[Fruit].GetEnumUnderlyingType() -eq [Int64]

Actual behavior

An exception is throw when the attempt to cast fails.

Enumerator value is too large for a System.Int.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

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-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions