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-8795] Runtime crash due to compiler failing to detect non-exhaustive switch case over complex enum structure #51303

Closed
swift-ci opened this issue Sep 19, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8795
Radar rdar://problem/44605024
Original Reporter luiz (JIRA User)
Type Bug
Status Closed
Resolution Cannot Reproduce
Environment

Xcode 10.0 (10A255)
Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin17.7.0

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

md5: 1fb7e4afac4972a0c1f68207981435b1

Issue Description:

The following sample produces a runtime crash due to the switch not complaining about missing cases/default case

indirect public enum SwiftType {
    case nested(NestedSwiftType)
    case nominal(NominalSwiftType)
    case optional(SwiftType)
}

public enum NominalSwiftType {
    case typeName(String)
    case generic(String, parameters: GenericArgumentSwiftType)
}

public enum ProtocolCompositionComponent {
    case nominal(NominalSwiftType)
    case nested(NestedSwiftType)
}

public enum TupleSwiftType {
    case types(TwoOrMore<SwiftType>)
    case empty
}

public typealias NestedSwiftType = TwoOrMore<NominalSwiftType>
public typealias GenericArgumentSwiftType = OneOrMore<SwiftType>

// MARK: - Building structures
public enum OneOrMore<T> {
    indirect case list(T, OneOrMore)
    case tail(T)
}

public enum TwoOrMore<T> {
    indirect case list(T, TwoOrMore)
    case tail(T, T)
}

func crashMe() {
    
    let unaliasedType = SwiftType.nominal(.typeName("TypeA"))
    let unaliasedBaseType = SwiftType.optional(.nominal(.typeName("TypeB")))
    
    // No complaints about non-exhaustive switch here!
    switch (unaliasedType, unaliasedBaseType) {
    case (.nominal, .nominal):
        break
        // Uncomment to fix crash
//    default:
//        break
    }
    
}

crashMe()
@belkadan
Copy link
Contributor

cc @xedin, CodaFi (JIRA User) (and me)

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Luiz Fernando Silva (JIRA)

As of Xcode 11.4.1 / Swift 5.2, the compiler correctly recognizes the switch as non-exhaustive and the crash no longer occurs.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

3 participants