diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index afda4b31394b0..bcc5454c29474 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -379,8 +379,9 @@ static bool doesAccessorNeedDynamicAttribute(AccessorDecl *accessor) { CtorInitializerKind InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const { auto &diags = decl->getASTContext().Diags; + auto dc = decl->getDeclContext(); - if (auto nominal = decl->getDeclContext()->getSelfNominalTypeDecl()) { + if (auto nominal = dc->getSelfNominalTypeDecl()) { // Convenience inits are only allowed on classes and in extensions thereof. if (auto convenAttr = decl->getAttrs().getAttribute()) { @@ -390,6 +391,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const { diags.diagnose(decl->getLoc(), diag::no_convenience_keyword_init, "actors") .fixItRemove(convenAttr->getLocation()) + .warnInSwiftInterface(dc) .warnUntilSwiftVersion(6); } else { // not an actor @@ -447,7 +449,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const { // (or the same file) to add vtable entries, we can re-evaluate this // restriction. if (!decl->isSynthesized() && - isa(decl->getDeclContext()->getImplementedObjCContext()) && + isa(dc->getImplementedObjCContext()) && !(decl->getAttrs().hasAttribute())) { if (classDcl->getForeignClassKind() == ClassDecl::ForeignKind::CFType) { @@ -476,7 +478,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const { } // end of Nominal context // initializers in protocol extensions must be convenience inits - if (decl->getDeclContext()->getExtendedProtocolDecl()) { + if (dc->getExtendedProtocolDecl()) { return CtorInitializerKind::Convenience; } diff --git a/test/ModuleInterface/actor_init.swift b/test/ModuleInterface/actor_init.swift new file mode 100644 index 0000000000000..2a89b2e595b78 --- /dev/null +++ b/test/ModuleInterface/actor_init.swift @@ -0,0 +1,22 @@ +// RUN: %empty-directory(%t) + +// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library +// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library +// RUN: %FileCheck %s --check-prefixes=CHECK < %t/Library.swiftinterface + +// Re-verify with -swift-version 6 +// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -swift-version 6 -module-name Library +// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library +// RUN: %FileCheck %s --check-prefixes=CHECK < %t/Library.swiftinterface + +// CHECK-LABEL: public actor TestActor { +@available(SwiftStdlib 5.5, *) +public actor TestActor { + // FIXME: The convenience keyword should be omitted (rdar://130926278) + // CHECK: public convenience init(convenience: Swift.Int) + public init(convenience: Int) { + self.init() + } + // CHECK: public init() + public init() {} +}