Swift: Printing an optional value causes a test to pass that otherwise (erroneously) fails

Originator:rix.rob
Number:rdar://19673469 Date Originated:30-Jan-2015 10:22 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1.1 (6A2008a)
Classification:Security Reproducible:Always
 
Summary:
Some combination of factors that I can’t reduce is causing a really awful bug where a non-nil value is branched on as though nil, unless I print it first.

Don’t ask me.


Steps to Reproduce:
1. Check out this repo, and all of its submodules, at the branch on this pull request: https://github.com/antitypical/Tesseract.framework/pull/22
2. Open Tesseract.xcworkspace
3. Run the tests (⌘U)
4. Note that two tests fail in EnvironmentTests.swift

NB: They shouldn’t—the value _is not nil_ (as can be verified in the debugger).

5. In EnvironmentTests.swift, uncomment the println(e) line.
6. Run the tests (⌘U)
7. Note that the tests pass (!!!)


Expected Results:
I expected the tests to pass in the first place, as the value is not nil.


Actual Results:
Amazingly, commenting out and uncommenting the println causes the tests to fail and pass respectively. I can only assume the compiler is generating bad code somewhere in there—possibly something to do with the @autoclosures in assertNotNil (see Assertions.swift), but I dunno.


Regression:
N/A


Notes:
N/A

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!