Skip to content

Commit e2c2f9d

Browse files
authored
Merge pull request #75642 from tshortli/module-interface-actor-extension-convenience-init
AST: Resume printing `convenience` on actor initializers
2 parents f810cbb + 2899aa5 commit e2c2f9d

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,13 +4280,15 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
42804280
// Protocol extension initializers are modeled as convenience initializers,
42814281
// but they're not written that way in source. Check if we're actually
42824282
// printing onto a class.
4283-
ClassDecl *classDecl = CurrentType
4284-
? CurrentType->getClassOrBoundGenericClass()
4285-
: decl->getDeclContext()->getSelfClassDecl();
4286-
if (classDecl) {
4287-
// Convenience intializers are also unmarked on actors.
4288-
if (!classDecl->isActor())
4289-
Printer.printKeyword("convenience", Options, " ");
4283+
bool isClassContext;
4284+
if (CurrentType) {
4285+
isClassContext = CurrentType->getClassOrBoundGenericClass() != nullptr;
4286+
} else {
4287+
const DeclContext *dc = decl->getDeclContext();
4288+
isClassContext = dc->getSelfClassDecl() != nullptr;
4289+
}
4290+
if (isClassContext) {
4291+
Printer.printKeyword("convenience", Options, " ");
42904292
} else {
42914293
assert(decl->getDeclContext()->getExtendedProtocolDecl() &&
42924294
"unexpected convenience initializer");

test/ModuleInterface/actor_init.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,29 @@
1212
// CHECK-LABEL: public actor TestActor {
1313
@available(SwiftStdlib 5.5, *)
1414
public actor TestActor {
15-
// CHECK: public init(convenience: Swift.Int)
16-
public init(convenience: Int) {
17-
self.init()
15+
private var x: Int
16+
17+
// CHECK: public convenience init(convenience x: Swift.Int)
18+
public init(convenience x: Int) {
19+
self.init(designated: x)
1820
}
21+
1922
// CHECK: public init()
20-
public init() {}
23+
public init() {
24+
self.x = 0
25+
}
26+
27+
// CHECK: public init(designated x: Swift.Int)
28+
public init(designated x: Int) {
29+
self.x = x
30+
}
31+
}
32+
33+
// CHECK-LABEL: extension Library.TestActor {
34+
@available(SwiftStdlib 5.5, *)
35+
extension TestActor {
36+
// CHECK: public convenience init(convenienceInExtension x: Swift.Int)
37+
public init(convenienceInExtension x: Int) {
38+
self.init(designated: x)
39+
}
2140
}

0 commit comments

Comments
 (0)