Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-4822] Exhaustive switch not recognized as such #47399

Closed
palimondo mannequin opened this issue May 7, 2017 · 2 comments
Closed

[SR-4822] Exhaustive switch not recognized as such #47399

palimondo mannequin opened this issue May 7, 2017 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@palimondo
Copy link
Mannequin

palimondo mannequin commented May 7, 2017

Previous ID SR-4822
Radar None
Original Reporter @palimondo
Type Bug
Status Resolved
Resolution Done
Environment

Xcode Version 8.3.2 (8E2002)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 41c7e0804bcad5e73e75451325560336

relates to:

  • SR-483 Exhaustivity checking for switch statement with wildcards doesn't work properly

Issue Description:

_emphasized text_The switch in append method is IMO exhaustive, but the compiler say "Switch must be exhaustive, consider adding a default clause".

fileprivate enum Storage : ExpressibleByArrayLiteral {
    typealias Element = Int
    case empty
    case single(Int)
    case pair(Int, Int)
    case array([Int])
    
    init(arrayLiteral elements: Int...) {
        self.init(elements)
    }
    
    init(_ elements: [Int]) {
        switch elements.count {
        case 0:
            self = .empty
            break
        case 1:
            self = .single(elements[0])
            break
        case 2:
            self = .pair(elements[0], elements[1])
            break
        default:
            self = .array(elements)
            break
        }
    }
    
    
    mutating func append(contentsOf other: Storage) {
        switch (self, other) {
        case (_, .empty):
            // DO NOTHING
            break
        case (.empty, _):
            self = other
            break
        case (.single(let first), .single(let second)):
            self = .pair(first, second)
            break
        case (.single(let first), .pair(let second, let third)),
             (.pair(let first, let second), .single(let third)):
            self = .array([first, second, third])
            break
        case (.pair(let first, let second), .pair(let third, let fourth)):
            self = .array([first, second, third, fourth])
            break
        case (.single(let first), .array(let rhsIndexes)):
            self = .array([first] + rhsIndexes)
            break
        case (.pair(let first, let second), .array(let indexes)):
            self = .array([first, second] + indexes)
            break
        case (.array(let indexes), .single(let first)):
            self = .array(indexes + [first])
            break
        case (.array(let indexes), .pair(let first, let second)):
            self = .array(indexes + [first, second])
            break
        case (.array(let lhsIndexes), .array(let rhsIndexes)):
            self = .array(lhsIndexes + rhsIndexes)
            break
        }
        
    }
}
@CodaFi
Copy link
Member

CodaFi commented May 7, 2017

Fixed on master and in 4.0 by #8908.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented May 7, 2017

Thanks CodaFi (JIRA User)!

If I understand the Jira issue lifecycle, we Close this once 4.0 ships, right? (Stays Resolved Done until then.)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant