Enumerating an implicitly unwrapped String causes SourceKit and the compiler to report an error

Originator:joaquimlobosilva
Number:rdar://17223313 Date Originated:08-Jun-2014 06:01 PM
Status:Duplicate of 17154593 Resolved:
Product:Developer Tools Product Version:6.0
Classification:UI/Usability Reproducible:Always
 
Summary:
In Swift, if a variable of type String! (implicitly unwrapped optional) is declared, and then iterated upon using the for-in syntax, Xcode reports an error with the SourceKitService and the editor loses all main functionality, such as syntax highlighting and proper indentation (screenshot attached). Compiling the program also returns an error. (Screenshot attached)

This only works with implicitly unwrapped optional values of String; regular String values work just fine.

Steps to Reproduce:
1. Create a new Xcode project (I created a View-based Cocoa Touch application, written in Swift)
2. In any part of the code, declare a String! variable as such:
var string: String! = "This is a string"

3. Immediately after that line, attempt to enumerate through the string using the for-in syntax, as such:

for character in string { }

4. After typing the first brace, Xcode should report the error.

Expected Results:
The editor should continue working normally, and the code should either compile or at least return a more descriptive error.

Actual Results:
Xcode reports an error with the SourceKitService module, and until the code is either removed or 'fixed', the problem will keep getting reported and all basic code editor functionality is disabled. Compiling the program also returns an error. (Screenshot attached)

Version:
Xcode Version 6.0 (6A215l), Mac OS X 10.9.3 (13D65)

Configuration:
I have only been able to test this on one machine—a Retina MacBook Pro (Late 2013, 15", high-end stock model) running OS X 10.9.3.

Attachments:
'Compiler Error.png' and 'SourceKitService crash.png' were successfully uploaded.

Comments

Running the same code in the REPL environment causes a segmentation fault:

1> var str: String! = "Hey this is a string" str: String! = "Hey this is a string" 2> for char in str {} Segmentation fault: 11

By joaquimlobosilva at June 15, 2014, 1:03 a.m. (reply...)

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!