Skip to content

[6.0] Sema: Downgrade actor convenience initializer diagnostic to a warning in interfaces. #74878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConvenienceAttr>()) {
Expand All @@ -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
Expand Down Expand Up @@ -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<ExtensionDecl>(decl->getDeclContext()->getImplementedObjCContext()) &&
isa<ExtensionDecl>(dc->getImplementedObjCContext()) &&
!(decl->getAttrs().hasAttribute<DynamicReplacementAttr>())) {

if (classDcl->getForeignClassKind() == ClassDecl::ForeignKind::CFType) {
Expand Down Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions test/ModuleInterface/actor_init.swift
Original file line number Diff line number Diff line change
@@ -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() {}
}