[swift-dev] why are we accepting switch statements with duplicate conditions?

Ted Kremenek kremenek at apple.com
Wed Sep 14 12:25:46 CDT 2016


Hi everyone,

Joe Shajrawi nominated an optimizer fix for Swift 3.0.1 where the optimizer was crashing due to duplicate conditions in aswitchstatement:

https://bugs.swift.org/browse/SR-2512 <https://bugs.swift.org/browse/SR-2512>
https://github.com/apple/swift/pull/4747 <https://github.com/apple/swift/pull/4747>
Here’s an example:

public enum DemoEnum {
    case firstCase
    case secondCase

    public static func performSwitch(with value: Int) -> DemoEnum {
        switch value {
        case 0:
            return DemoEnum.firstCase
        case 0:
            return DemoEnum.firstCase
        default:
            return DemoEnum.secondCase
        }
    }
}
I can’t remember why the frontend even accepts this code. Is this intended, or just a defect in the compiler’s validity checking ofswitch statements?

Thanks,
Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160914/5a882d44/attachment.html>


More information about the swift-dev mailing list