Xcode 6.1.1: Swift compiler pretends that code is unreachable but it is
| Originator: | weissismail | ||
| Number: | rdar://19593095 | Date Originated: | 25-Jan-2015 07:12 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1.1 (6A2008a) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
In the function test of the (arguably useless) Swift program below all code is reachable (depends on the value of the boolean parameter `b`):
--- SNIP ---
import Darwin.C.stdlib
func test(b:Bool) -> ((), ()) {
return (b ? exit(1) : (), ())
}
print("\(test(true))\n")
--- SNAP ---
However the compiler pretends that `exit(1)` would be unreachable:
$ xcrun -sdk macosx swiftc main.swift
main.swift:4:17: warning: will never be executed
return (b ? exit(1) : (), ())
^ (this carent points the the "e" of "exit(1)")
main.swift:4:17: note: a call to a noreturn function
return (b ? exit(1) : (), ())
^ (this carent points the the "e" of "exit(1)")
Steps to Reproduce:
1. Download the attached swift program (main.swift) and save as /tmp/main.swift
2. xcrun -sdk macosx swiftc /tmp/main.swift
Expected Results:
swiftc exits successfully and doesn't output anything
Actual Results:
swiftc outputs a warning about unreachable code but still compiles the program
Regression:
not that I'd be aware of
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!