AST: Don't print convenience on actor initializers.

Although actor initializers can be classified as convenience initializers by
the internals of the compiler, they are not written that way in source and
should not be printed with the `convenience` keyword.

Resolves rdar://130926278.
This commit is contained in:
Allan Shortlidge
2024-07-11 11:43:51 -07:00
parent a55beaa79d
commit 3453b136c3
2 changed files with 8 additions and 11 deletions

View File

@@ -4285,15 +4285,13 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
// Protocol extension initializers are modeled as convenience initializers, // Protocol extension initializers are modeled as convenience initializers,
// but they're not written that way in source. Check if we're actually // but they're not written that way in source. Check if we're actually
// printing onto a class. // printing onto a class.
bool isClassContext; ClassDecl *classDecl = CurrentType
if (CurrentType) { ? CurrentType->getClassOrBoundGenericClass()
isClassContext = CurrentType->getClassOrBoundGenericClass() != nullptr; : decl->getDeclContext()->getSelfClassDecl();
} else { if (classDecl) {
const DeclContext *dc = decl->getDeclContext(); // Convenience intializers are also unmarked on actors.
isClassContext = dc->getSelfClassDecl() != nullptr; if (!classDecl->isActor())
} Printer.printKeyword("convenience", Options, " ");
if (isClassContext) {
Printer.printKeyword("convenience", Options, " ");
} else { } else {
assert(decl->getDeclContext()->getExtendedProtocolDecl() && assert(decl->getDeclContext()->getExtendedProtocolDecl() &&
"unexpected convenience initializer"); "unexpected convenience initializer");

View File

@@ -12,8 +12,7 @@
// CHECK-LABEL: public actor TestActor { // CHECK-LABEL: public actor TestActor {
@available(SwiftStdlib 5.5, *) @available(SwiftStdlib 5.5, *)
public actor TestActor { public actor TestActor {
// FIXME: The convenience keyword should be omitted (rdar://130926278) // CHECK: public init(convenience: Swift.Int)
// CHECK: public convenience init(convenience: Swift.Int)
public init(convenience: Int) { public init(convenience: Int) {
self.init() self.init()
} }