mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The compiler now diagnoses appropriately the case where a super.init() is marked as throwing while a subclass' initializer isn't marked as throwing nor explicitly calls the super.init().
25 lines
1.1 KiB
Swift
25 lines
1.1 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
class ThrowingInitSuperclass {
|
|
init() throws { }
|
|
}
|
|
|
|
// Implicitly calling the super.init IS possible here because the initializer
|
|
// is a throwing initializer.
|
|
class ThrowingInitClass: ThrowingInitSuperclass {
|
|
init(simpleArgument: Int) throws { }
|
|
}
|
|
|
|
// Implicitly calling the super.init IS NOT possible here because the
|
|
// initializer is not a throwing initializer.
|
|
class NonThrowingInitClass: ThrowingInitSuperclass {
|
|
init(simpleArgument: Int) { } // expected-error {{missing call to superclass's initializer; 'super.init' is a throwing initializer and requires either an explicit call or that this initializer is also marked as 'throws'}}
|
|
}
|
|
|
|
// Implicitly calling the super.init IS NOT possible here because the
|
|
// initializer is a rethrowing initializer, which means it can only
|
|
// rethrow errors from its parameters.
|
|
class RethrowingInitClass: ThrowingInitSuperclass {
|
|
init(throwingArgument: () throws -> Void) rethrows { } // expected-error {{missing call to superclass's initializer; 'super.init' is a throwing initializer and requires either an explicit call or that this initializer is also marked as 'throws'}}
|
|
}
|