Skip to content

Compiler crash for self reference in enum with no cases #66384

Open
@rudro

Description

@rudro

Description

import Foundation

enum MySwitch {
    public var generatedExperimentKey: String {
        switch self {
            default: fatalError()
        }
        //return ""
    }
}

Steps to reproduce
Save the code above to file. Run swiftc someFile.swift.

Note: Uncomment the return to fix the crash. It produces a "will never reach" warning, but also a "note: 'self' is of type 'MySwitch' which cannot be constructed because it is an enum with no cases"

Expected behavior
Compiler should not crash.

Swift 5.9 (swiftlang-5.9.0.114.6 clang-1500.0.27.1)
Xcode 15.0 Build version 15A5160n

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stageassertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaredeclarationsFeature: declarationsenumFeature → type declarations: Swift enumeration declarationsexpressionsFeature: expressionsselfFeature → expressions: The 'self' expressionstatementsFeature: statementsswift 5.9switchFeature → statements: 'switch' statements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions