Skip to content

[SR-1056] Type check can result in crash #43668

@swift-ci

Description

@swift-ci
Previous ID SR-1056
Radar rdar://problem/25339123
Original Reporter Abadjiev (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode Version 7.3 (7D175)

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

md5: 6427dd7d1f2a9ce900f43e3cb7b07ed6

Issue Description:

With Swift 2.2 a certain type check can results in 100% reproducible crash. The key components are:

  1. Have a class with an optional Generic field

  2. Have a enum type to check against

  3. Use a Struct with at least one String field and 2 String? fields

  4. Check value type with `is` using the optional Enum type notation

  5. 100% guaranteed crash, usually "error: memory read failed for 0x0

This construction works as expected in previous versions of Swift (2.1, 2.0 and etc).

Example:

enum AnEnum {}

class AClass<T> {
    var v: T?
    
    func isEnumOptType() -> Bool {
        return v is AnEnum?
    }
    
}

struct AStruct {
    
    let s1: String
    let optS1: String?
    let optS2: String?
    
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {        
        let ss = AClass<AStruct>()
        ss.isEnumOptType()
        // crash will occur here or with the next statement if any
        //  ....

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 executionswift 2.2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions