Description
Description
Reproducible crash of compiled code, but without a compiler warning or error.
(Usage of try outside of do - catch block)
enum AnotherError: Error {
case badThing
}
func alwaysThrows() throws {
throw AnotherError.badThing
}
do {
try alwaysThrows() // this try is fine
} catch {
print("It did throw fine")
}
try alwaysThrows() // <-- compiler should give a warning or an error, forcing try? or try!
Steps to reproduce
Run the code above, the marked line will not generate a compiler warning or error, but will crash the program.
Expected behavior
I would prefer the compiler to not allow try outside of a do-catch block (error). If for some reason that is not feasible, at least an warning should be thrown (though I would prefer an error, to make it clear to the user)
Environment
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: x86_64-apple-macosx12.0
Xcode 14.1
Build version 14B47b
I also upgraded to latest Xcode version to ensure it hasn't been fixed already_
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: x86_64-apple-macosx12.0
Xcode 14.2
Build version 14C18
Issue still present with latest version.
Deployment target was MacOS 12.6 (21G115) - but probably doesn't matter
Please let me know if you need any additional information on this report.
Kind regards,
Heiko