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) {
4280
4280
// Protocol extension initializers are modeled as convenience initializers,
4281
4281
// but they're not written that way in source. Check if we're actually
4282
4282
// 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, " " );
4290
4292
} else {
4291
4293
assert (decl->getDeclContext ()->getExtendedProtocolDecl () &&
4292
4294
" unexpected convenience initializer" );
Original file line number Diff line number Diff line change 12
12
// CHECK-LABEL: public actor TestActor {
13
13
@available ( SwiftStdlib 5 . 5 , * )
14
14
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)
18
20
}
21
+
19
22
// 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
+ }
21
40
}
You can’t perform that action at this time.
0 commit comments