File tree Expand file tree Collapse file tree 4 files changed +1319
-985
lines changed
test/SourceKit/DocSupport Expand file tree Collapse file tree 4 files changed +1319
-985
lines changed Original file line number Diff line number Diff line change @@ -2707,10 +2707,25 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
2707
2707
if ((decl->getInitKind () == CtorInitializerKind::Convenience ||
2708
2708
decl->getInitKind () == CtorInitializerKind::ConvenienceFactory) &&
2709
2709
!decl->getAttrs ().hasAttribute <ConvenienceAttr>()) {
2710
- Printer.printKeyword (" convenience" );
2711
- Printer << " " ;
2710
+ // Protocol extension initializers are modeled as convenience initializers,
2711
+ // but they're not written that way in source. Check if we're actually
2712
+ // printing onto a class.
2713
+ bool isClassContext;
2714
+ if (CurrentType) {
2715
+ isClassContext = CurrentType->getClassOrBoundGenericClass () != nullptr ;
2716
+ } else {
2717
+ const DeclContext *dc = decl->getDeclContext ();
2718
+ isClassContext = dc->getSelfClassDecl () != nullptr ;
2719
+ }
2720
+ if (isClassContext) {
2721
+ Printer.printKeyword (" convenience" );
2722
+ Printer << " " ;
2723
+ } else {
2724
+ assert (decl->getDeclContext ()->getExtendedProtocolDecl () &&
2725
+ " unexpected convenience initializer" );
2726
+ }
2712
2727
} else if (decl->getInitKind () == CtorInitializerKind::Factory) {
2713
- Printer << " /*not inherited*/ " ;
2728
+ Printer << " /*not inherited*/ " ;
2714
2729
}
2715
2730
2716
2731
printContextIfNeeded (decl);
Original file line number Diff line number Diff line change @@ -29,3 +29,19 @@ public extension P2 where Self : P3 {
29
29
public extension Dictionary . Keys {
30
30
public func foo( ) { }
31
31
}
32
+
33
+ public protocol InitProto {
34
+ init ( x: Int )
35
+ }
36
+ extension InitProto {
37
+ // This initializer is marked as 'CtorInitializerKind::Convenience'.
38
+ public init ( ) { self = Self ( x: 0 ) }
39
+ }
40
+
41
+ public struct InitStructImpl : InitProto {
42
+ public init ( x: Int ) { }
43
+ }
44
+
45
+ public class InitClassImpl : InitProto {
46
+ public required init ( x: Int ) { }
47
+ }
You can’t perform that action at this time.
0 commit comments