File tree Expand file tree Collapse file tree 2 files changed +32
-11
lines changed
Expand file tree Collapse file tree 2 files changed +32
-11
lines changed Original file line number Diff line number Diff 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" );
Original file line number Diff line number Diff line change 1212// CHECK-LABEL: public actor TestActor {
1313@available ( SwiftStdlib 5 . 5 , * )
1414public 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}
You can’t perform that action at this time.
0 commit comments