Files
swift-mirror/test/Sema/throwing_super_init.swift
Visckmart b93273951f [Sema] Fix throwing super.init() diagnostics
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().
2023-11-08 12:42:03 -03:00

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'}}
}