diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 3b6abcfca8c92..6ee01f0061f77 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -378,8 +378,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()) { @@ -389,6 +390,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 @@ -446,7 +448,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) { @@ -475,7 +477,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..3ca3a66902911 --- /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.1, *) +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() {} +}