Swift Compile Error when Casting in certain scenario
Originator: | rcdilorenzo | ||
Number: | rdar://17312149 | Date Originated: | |
Status: | Open | Resolved: | |
Product: | iOS SDK | Product Version: | 8.0 |
Classification: | Serious Bug | Reproducible: | Always |
Summary: In this specific scenario, I type cast a value coming from a dictionary to a string, but the program doesn’t compile and blows up with a swift compile error (segmentation fault 11) Steps to Reproduce: 1. Write the following code: === Begin Code ==== import Foundation class DateJSONMapper: JSONMapping { let jsonKey : String let objectKey : String let dateFormatter : NSDateFormatter init(jsonKey: String, objectKey: String, dateFormatter: NSDateFormatter) { self.jsonKey = jsonKey self.objectKey = objectKey self.dateFormatter = dateFormatter } func applyTo(object: NSObject, json: Dictionary<String, AnyObject>) { let dateString = json[jsonKey] as String? // <— This is the line that breaks; compiles fine if I use ”\(json[jsonKey])” instead let value = dateFormatter.dateFromString(dateString) object.setValue(value, forKey: objectKey) } } === End Code === 2. Compile Expected Results: I expected it to compile and run the tests for my app against this code. Actual Results: The syntax flickers out and I get a “SourceKitService” interrupted and I get an obscure swift compile/parse error as follows: === Begin Log === 1. While type-checking 'applyTo' at /Users/christiandilorenzo/workspaces/JSONMapper/JSONMapper/DateJSONMapper.swift:32:5 2. While type-checking declaration at /Users/christiandilorenzo/workspaces/JSONMapper/JSONMapper/DateJSONMapper.swift:33:9 3. While type-checking expression at [/Users/christiandilorenzo/workspaces/JSONMapper/JSONMapper/DateJSONMapper.swift:33:26 - line:33:49] RangeText="json[jsonKey] as String?" <unknown>:0: error: unable to execute command: Segmentation fault: 11 <unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation) === End Log === Version: iOS 8.0 Notes: Configuration: MacBook Pro Retina Display (Using iPhone 4s and 5s simulator per chance)
Comments
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!