Skip to content

Commit de144e9

Browse files
authored
Merge pull request #74878 from tshortli/module-interface-suppress-actor-convenience-init-diag-6.0
[6.0] Sema: Downgrade actor convenience initializer diagnostic to a warning in interfaces.
2 parents 09b8b08 + dfdb161 commit de144e9

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,9 @@ static bool doesAccessorNeedDynamicAttribute(AccessorDecl *accessor) {
378378
CtorInitializerKind
379379
InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const {
380380
auto &diags = decl->getASTContext().Diags;
381+
auto dc = decl->getDeclContext();
381382

382-
if (auto nominal = decl->getDeclContext()->getSelfNominalTypeDecl()) {
383+
if (auto nominal = dc->getSelfNominalTypeDecl()) {
383384

384385
// Convenience inits are only allowed on classes and in extensions thereof.
385386
if (auto convenAttr = decl->getAttrs().getAttribute<ConvenienceAttr>()) {
@@ -389,6 +390,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const {
389390
diags.diagnose(decl->getLoc(),
390391
diag::no_convenience_keyword_init, "actors")
391392
.fixItRemove(convenAttr->getLocation())
393+
.warnInSwiftInterface(dc)
392394
.warnUntilSwiftVersion(6);
393395

394396
} else { // not an actor
@@ -446,7 +448,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const {
446448
// (or the same file) to add vtable entries, we can re-evaluate this
447449
// restriction.
448450
if (!decl->isSynthesized() &&
449-
isa<ExtensionDecl>(decl->getDeclContext()->getImplementedObjCContext()) &&
451+
isa<ExtensionDecl>(dc->getImplementedObjCContext()) &&
450452
!(decl->getAttrs().hasAttribute<DynamicReplacementAttr>())) {
451453

452454
if (classDcl->getForeignClassKind() == ClassDecl::ForeignKind::CFType) {
@@ -475,7 +477,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const {
475477
} // end of Nominal context
476478

477479
// initializers in protocol extensions must be convenience inits
478-
if (decl->getDeclContext()->getExtendedProtocolDecl()) {
480+
if (dc->getExtendedProtocolDecl()) {
479481
return CtorInitializerKind::Convenience;
480482
}
481483

test/ModuleInterface/actor_init.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
4+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
5+
// RUN: %FileCheck %s --check-prefixes=CHECK < %t/Library.swiftinterface
6+
7+
// Re-verify with -swift-version 6
8+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -swift-version 6 -module-name Library
9+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
10+
// RUN: %FileCheck %s --check-prefixes=CHECK < %t/Library.swiftinterface
11+
12+
// CHECK-LABEL: public actor TestActor {
13+
@available(SwiftStdlib 5.1, *)
14+
public actor TestActor {
15+
// FIXME: The convenience keyword should be omitted (rdar://130926278)
16+
// CHECK: public convenience init(convenience: Swift.Int)
17+
public init(convenience: Int) {
18+
self.init()
19+
}
20+
// CHECK: public init()
21+
public init() {}
22+
}

0 commit comments

Comments
 (0)