Swift 2: Crash compiling autoclosure passed to function returning optional in closure passed to function
| Originator: | rix.rob | ||
| Number: | rdar://21326177 | Date Originated: | 10-Jun-2015 03:55 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-7-beta (7A120f) |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
Summary:
It’s a bit weird.
This one hit me when converting https://github.com/antitypical/Assertions — tests of assertion failures have this pattern.
Steps to Reproduce:
1. This:
func a(@autoclosure _ : () -> Int) -> Int? { return nil }
func b(_ : () -> ()) {}
b {
a(0)
}
Expected Results:
should not crash the compiler
Actual Results:
but it does:
Assertion failed: (discriminator != AbstractClosureExpr::InvalidDiscriminator && "closure must be marked correctly with discriminator"), function mangleClosureComponents, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.38.1/src/swift/lib/AST/Mangle.cpp, line 1396.
0 swift 0x00000001093d9e0b llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x00000001093da54b SignalHandler(int) + 379
2 libsystem_platform.dylib 0x00007fff88493f1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fcb58874200 _sigtramp + 3493724928
4 libsystem_c.dylib 0x00007fff86f90b53 abort + 129
5 libsystem_c.dylib 0x00007fff86f58c39 basename + 0
6 swift 0x0000000107b7b7b9 swift::Mangle::Mangler::mangleClosureComponents(swift::Type, unsigned int, bool, swift::DeclContext const*, swift::DeclContext const*) + 313
7 swift 0x00000001075c9083 swift::SILDeclRef::mangle(llvm::SmallVectorImpl<char>&, llvm::StringRef) const + 1811
8 swift 0x0000000107578e36 swift::SILModule::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t) + 86
9 swift 0x00000001075e61d8 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 264
10 swift 0x00000001075eaaec swift::SILFunction* swift::Lowering::SILGenModule::preEmitFunction<swift::AbstractClosureExpr>(swift::SILDeclRef, swift::AbstractClosureExpr*, swift::SILLocation) + 108
…
Stack dump:
0. Program arguments: /Applications/Xcode-7-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret ./recur.swift -target x86_64-apple-darwin14.3.0 -enable-objc-interop -sdk /Applications/Xcode-7-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -module-name recur
1. While silgen closureexpr SIL function @_TF5recurU_FT_T_ for expression at [./recur.swift:5:3 - line:7:1] RangeText="{
a(0)
}"
Regression:
Swift 1.2 didn’t crash with this.
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!