Skip to content

[SR-887] Expose the declaration order of Enum cases with payloads #43499

@masters3d

Description

@masters3d
Previous ID SR-887
Radar None
Original Reporter @masters3d
Type Improvement
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 8985ba38c2b176524ace48d4f576b55c

Issue Description:

error:
"Enum with raw type cannot have cases with arguments"

In addition to being able to carry a payload, it would be really useful if enums could also have a way to expose their order as an Int or some sort of Index Raw type so they can be ranked by importance.

BEFORE
```
enum HandRank{
    case highCard(PlayingCard)
    case onePair(Rank,card1:Rank, card2:Rank, card3:Rank )
    case twoPair(high:Rank,low:Rank, highCard:PlayingCard)
    case threeOfAKind(three:Rank)
    case straight(high:Rank)
    case flush(Rank, Suit)
    case fullHouse(three:Rank)
    case fourOfAKind(four:Rank)
    case straightFlush(Rank,Suit)
    
    func order()->Int{
        switch self {
        case .highCard(_): return 1
        case .onePair(_, card1: _, card2: _, card3: _): return 2
        case .twoPair(high: _, low: _, highCard: _): return 3
        case threeOfAKind(three:_): return 4
        case straight(high:_): return 5
        case flush(_, _): return 6
        case fullHouse(three:_): return 7
        case fourOfAKind(four:_): return 8
        case straightFlush(_,_): return 9
        }
    }
.........
}

```

AFTER:

```
enum HandRank:Int{
    case highCard(PlayingCard) = 1
    case onePair(Rank,card1:Rank, card2:Rank, card3:Rank )
    case twoPair(high:Rank,low:Rank, highCard:PlayingCard)
    case threeOfAKind(three:Rank)
    case straight(high:Rank)
    case flush(Rank, Suit)
    case fullHouse(three:Rank)
    case fourOfAKind(four:Rank)
    case straightFlush(Rank,Suit)
.....
}
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerThe Swift compiler itselffeatureA feature request or implementationimprovement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions