Swift 2: Type is not dynamically inferred in if statement that is using "is" keyword

Originator:tmk.szlc
Number:rdar://21965532 Date Originated:23 Jul 2015
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 2.0
Classification:Other Bug Reproducible:Always
 
Summary:
Swift should infer type of a variable if it knows that if-statement checks for some concrete type. Take a look on example to get the idea.

protocol Wehicle {}

struct Car: Wehicle {
    func getIn() {}
}

struct Bike: Wehicle {
    func getOn() {}
}

var wehicle: Wehicle = Car()

if wehicle is Car {
    wehicle.getIn() // Error: Wehicle does not have a member getIn()
    // (wehicle as! Car).getIn() works
} else if wehicle is Bike {
    wehicle.getOn() // Error, Wehicle does not have a member getOn()
    // (wehicle as! Bike).getOn() works
}

Steps to Reproduce:
Paste the code to new playground using Xcode 7 beta 4

Expected Results:
Compiler should infer type automatically.

Actual Results:
Compiler errors.

Version:
Xcode 7 beta 4, Swift 2.0

Notes:


Configuration:
Xcode 7 beta 4, Swift 2.0

Attachments:

Comments

`isis only used for checking, not casting. What you want to do is:if let wehicle = wehicle as? Car { wehicle.getIn() } else ... `


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!