Skip to content

Commit 8821e6c

Browse files
Matt Kiazykmattt
andauthored
Regression - private subclasses showing (SwiftDocOrg#131)
* Fix bug with private subclasses showing * Add changelog entries for SwiftDocOrg#131 Co-authored-by: Mattt <[email protected]>
1 parent bcab20a commit 8821e6c

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
#127 by @mattpolzin, @kareman, and @mattt.
2828
- Fixed display of sidebar icons.
2929
#145 by @mattt.
30+
- Fixed inclusion of non-public subclasses of public superclasses.
31+
#131 by @MattKiazyk.
3032

3133
## [1.0.0-beta.3] - 2020-05-19
3234

Sources/SwiftDoc/Interface.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ public final class Interface {
1515
self.topLevelSymbols = symbols.filter { $0.api is Type || $0.id.pathComponents.isEmpty }
1616

1717
self.relationships = {
18+
let symbols = symbols.filter { $0.isPublic }
1819
let extensionsByExtendedType: [String: [Extension]] = Dictionary(grouping: symbols.flatMap { $0.context.compactMap { $0 as? Extension } }, by: { $0.extendedType })
1920

2021
var relationships: Set<Relationship> = []
2122
for symbol in symbols {
23+
2224
let lastDeclarationScope = symbol.context.last(where: { $0 is Extension || $0 is Symbol })
2325

2426
if let container = lastDeclarationScope as? Symbol {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import XCTest
2+
3+
import SwiftDoc
4+
import SwiftSemantics
5+
import struct SwiftSemantics.Protocol
6+
import SwiftSyntax
7+
8+
final class InterfaceTypeTests: XCTestCase {
9+
10+
func testPrivateInheritance() throws {
11+
let source = #"""
12+
public class A { }
13+
14+
class B : A { }
15+
16+
public class C : A { }
17+
"""#
18+
19+
let url = try temporaryFile(contents: source)
20+
let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent())
21+
let module = Module(name: "Module", sourceFiles: [sourceFile])
22+
23+
// `class A`
24+
let classA = sourceFile.symbols[0]
25+
XCTAssert(classA.api is Class)
26+
27+
// `class B`
28+
let classB = sourceFile.symbols[1]
29+
XCTAssert(classB.api is Class)
30+
31+
// `class C`
32+
let classC = sourceFile.symbols[2]
33+
XCTAssert(classC.api is Class)
34+
35+
// Class B does not exist in subclasses because it's not public
36+
// Class C exists in subclasses because it's public
37+
let subclasses = module.interface.typesInheriting(from: classA)
38+
XCTAssertEqual(subclasses.count, 1)
39+
XCTAssertEqual(subclasses[0].id, classC.id)
40+
}
41+
}

0 commit comments

Comments
 (0)