From 3453b136c38a645073f6cb76d9f643bc5533c55c Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Thu, 11 Jul 2024 11:43:51 -0700 Subject: [PATCH] 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. --- lib/AST/ASTPrinter.cpp | 16 +++++++--------- test/ModuleInterface/actor_init.swift | 3 +-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index c8c8bb42a3b10..a1e7d4a4fd932 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -4285,15 +4285,13 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) { // Protocol extension initializers are modeled as convenience initializers, // but they're not written that way in source. Check if we're actually // printing onto a class. - bool isClassContext; - if (CurrentType) { - isClassContext = CurrentType->getClassOrBoundGenericClass() != nullptr; - } else { - const DeclContext *dc = decl->getDeclContext(); - isClassContext = dc->getSelfClassDecl() != nullptr; - } - if (isClassContext) { - Printer.printKeyword("convenience", Options, " "); + ClassDecl *classDecl = CurrentType + ? CurrentType->getClassOrBoundGenericClass() + : decl->getDeclContext()->getSelfClassDecl(); + if (classDecl) { + // Convenience intializers are also unmarked on actors. + if (!classDecl->isActor()) + Printer.printKeyword("convenience", Options, " "); } else { assert(decl->getDeclContext()->getExtendedProtocolDecl() && "unexpected convenience initializer"); diff --git a/test/ModuleInterface/actor_init.swift b/test/ModuleInterface/actor_init.swift index 2a89b2e595b78..40769cd895d39 100644 --- a/test/ModuleInterface/actor_init.swift +++ b/test/ModuleInterface/actor_init.swift @@ -12,8 +12,7 @@ // CHECK-LABEL: public actor TestActor { @available(SwiftStdlib 5.5, *) public actor TestActor { - // FIXME: The convenience keyword should be omitted (rdar://130926278) - // CHECK: public convenience init(convenience: Swift.Int) + // CHECK: public init(convenience: Swift.Int) public init(convenience: Int) { self.init() }