Swift: compiler crash when using defer in initializer of a class inheriting from another class
| Originator: | sash | ||
| Number: | rdar://22917580 | Date Originated: | 30-Sep-2015 10:44 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.0.1 (7A1001) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
Defer is a very convenient workaround for failable initialisers requiring to call super before returning nil. Sadly it crashes compiler
Steps to Reproduce:
Try running following code
class B {
init() {
}
}
class A: B {
override init() {
defer {
super.init()
}
}
}
let a = A()
Expected Results:
Initialisation should be invoked as the very last thing happening during initialisation.
Actual Results:
Compiler crashes with
0 swift 0x0000000110fbfedb llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x0000000110fc061b SignalHandler(int) + 379
4 swift 0x000000010f2abddd swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 24749
5 swift 0x000000010f2a44ad swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 397
6 swift 0x000000010f2e4e46 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 294
7 swift 0x000000010f2e4d15 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
8 swift 0x000000010f2b5e7b swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 331
9 swift 0x000000010f272a20 std::__1::__function::__func<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1, std::__1::allocator<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1>, void (swift::SILFunction*)>::operator()(swift::SILFunction*&&) + 128
10 swift 0x000000010f272474 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1268
11 swift 0x000000010f2726dd swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
12 swift 0x000000010f0d0fd5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11445
13 swift 0x000000010f0ce10a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2682
14 swift 0x000000010f0ca797 main + 2247
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!