File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
test/SymbolGraph/Relationships/DefaultImplementationOf Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -430,6 +430,17 @@ void SymbolGraph::recordDefaultImplementationRelationships(Symbol S) {
430
430
recordEdge (Symbol (this , VD, nullptr ),
431
431
Symbol (this , MemberVD, nullptr ),
432
432
RelationshipKind::DefaultImplementationOf ());
433
+
434
+ // If P is from a different module, and it's being added to a type
435
+ // from the current module, add a `memberOf` relation to the extended
436
+ // protocol.
437
+ if (MemberVD->getModuleContext ()->getNameStr () != M.getNameStr () && VD->getDeclContext ()) {
438
+ if (auto *ExP = VD->getDeclContext ()->getSelfNominalTypeDecl ()) {
439
+ recordEdge (Symbol (this , VD, nullptr ),
440
+ Symbol (this , ExP, nullptr ),
441
+ RelationshipKind::MemberOf ());
442
+ }
443
+ }
433
444
}
434
445
}
435
446
}
Original file line number Diff line number Diff line change
1
+ public protocol RemoteP {
2
+ func someFunc( )
3
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-build-swift %S/Inputs/RemoteP.swift -module-name RemoteP -emit-module -emit-module-path %t/
3
+ // RUN: %target-build-swift %s -module-name Remote -emit-module -emit-module-path %t/ -I %t
4
+ // RUN: %target-swift-symbolgraph-extract -module-name Remote -I %t -pretty-print -output-dir %t
5
+ // RUN: %FileCheck %s --input-file %t/Remote.symbols.json
6
+ // RUN: %FileCheck %s --input-file %t/Remote.symbols.json --check-prefix MEMBER
7
+
8
+ import RemoteP
9
+
10
+ public protocol LocalP : RemoteP { }
11
+
12
+ public extension LocalP {
13
+ func someFunc( ) { }
14
+ }
15
+
16
+ // default implementations that are for protocols in a different module should have a `memberOf`
17
+ // relation linking them to a local symbol, if one exists
18
+
19
+ // CHECK: "kind": "defaultImplementationOf"
20
+ // CHECK-NEXT: "source": "s:6Remote6LocalPPAAE8someFuncyyF"
21
+ // CHECK-NEXT: "target": "s:7RemotePAAP8someFuncyyF"
22
+ // CHECK-NEXT: "targetFallback": "RemoteP.RemoteP.someFunc()"
23
+
24
+ // MEMBER: "kind": "memberOf"
25
+ // MEMBER-NEXT: "source": "s:6Remote6LocalPPAAE8someFuncyyF"
26
+ // MEMBER-NEXT: "target": "s:6Remote6LocalPP"
You can’t perform that action at this time.
0 commit comments