Skip to content

[SR-7222] Accessing Dictionary from rawValue in enum causes runtime crash in Swift 4.1. #49770

Open
@swift-ci

Description

@swift-ci
Previous ID SR-7222
Radar rdar://problem/38624846
Original Reporter valleyman86 (JIRA User)
Type Bug
Environment

Xcode 9.3 beta 4 Swift 4.1

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

md5: 8861114e1b1eac9fc303c01bd4786968

Issue Description:

enum PlaydoughConfigView {
    case header
    case subtitle
    case art
    case progress
    case controls
    case bannerAds
}

enum PlaydoughConfig {
    case standard
    case basic
    case compactStandard
    case compactBasic
}

extension PlaydoughConfig: RawRepresentable {
    typealias RawValue = [PlaydoughConfigView]

    static let configs = [.standard: [.header, .art, .subtitle, .progress, .controls, .bannerAds],
                          .basic: [.header, .art, .subtitle, .progress, .controls],
                          .compactStandard: [.header, .art, .progress, .controls, .bannerAds],
                          .compactBasic: [.header, .art, .progress, .controls]] as [PlaydoughConfig: RawValue]

    init?(rawValue: RawValue) {
        if let key = PlaydoughConfig.configs.first(where: { rawValue == $1 })?.key {
            self = key
        }
        return nil
    }



    var rawValue: RawValue {
        return PlaydoughConfig.configs[self] ?? []
    }
}

let test = PlaydoughConfig.configs[.standard] // Crash

This is a regression from Swift 4.0. It seems the Dictionary.init is calling rawValue most likely due to equatable. This code works fine in 4.0 and crashes in 4.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareregressionrun-time crashBug → crash: Swift code crashed during executionstandard libraryArea: Standard library umbrellaswift 4.1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions