From 697ac1f7730587883458ab6ce4c86dfaa785131d Mon Sep 17 00:00:00 2001 From: Matt Kiazyk Date: Wed, 3 Jun 2020 14:41:33 -0500 Subject: [PATCH 1/2] Fix bug with private subclasses showing --- Sources/SwiftDoc/Interface.swift | 2 + Tests/SwiftDocTests/InterfaceTypeTests.swift | 41 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Tests/SwiftDocTests/InterfaceTypeTests.swift diff --git a/Sources/SwiftDoc/Interface.swift b/Sources/SwiftDoc/Interface.swift index c05e17ea..7b83e5a1 100644 --- a/Sources/SwiftDoc/Interface.swift +++ b/Sources/SwiftDoc/Interface.swift @@ -15,10 +15,12 @@ public final class Interface { self.topLevelSymbols = symbols.filter { $0.api is Type || $0.id.pathComponents.isEmpty } self.relationships = { + let symbols = symbols.filter { $0.isPublic } let extensionsByExtendedType: [String: [Extension]] = Dictionary(grouping: symbols.flatMap { $0.context.compactMap { $0 as? Extension } }, by: { $0.extendedType }) var relationships: Set = [] for symbol in symbols { + let lastDeclarationScope = symbol.context.last(where: { $0 is Extension || $0 is Symbol }) if let container = lastDeclarationScope as? Symbol { diff --git a/Tests/SwiftDocTests/InterfaceTypeTests.swift b/Tests/SwiftDocTests/InterfaceTypeTests.swift new file mode 100644 index 00000000..54c26cce --- /dev/null +++ b/Tests/SwiftDocTests/InterfaceTypeTests.swift @@ -0,0 +1,41 @@ +import XCTest + +import SwiftDoc +import SwiftSemantics +import struct SwiftSemantics.Protocol +import SwiftSyntax + +final class InterfaceTypeTests: XCTestCase { + + func testPrivateInheritance() throws { + let source = #""" + public class A { } + + class B : A { } + + public class C : A { } + """# + + let url = try temporaryFile(contents: source) + let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent()) + let module = Module(name: "Module", sourceFiles: [sourceFile]) + + // `class A` + let classA = sourceFile.symbols[0] + XCTAssert(classA.api is Class) + + // `class B` + let classB = sourceFile.symbols[1] + XCTAssert(classB.api is Class) + + // `class C` + let classC = sourceFile.symbols[2] + XCTAssert(classC.api is Class) + + // Class B does not exist in subclasses because it's not public + // Class C exists in subclasses because it's public + let subclasses = module.interface.typesInheriting(from: classA) + XCTAssertEqual(subclasses.count, 1) + XCTAssertEqual(subclasses[0].id, classC.id) + } +} From 5670a0d26b7be6a9f8a0c23b64566350d1e29a10 Mon Sep 17 00:00:00 2001 From: Mattt Date: Mon, 27 Jul 2020 11:17:44 -0700 Subject: [PATCH 2/2] Add changelog entries for #131 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 5306c43d..d3383b5f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #127 by @mattpolzin, @kareman, and @mattt. - Fixed display of sidebar icons. #145 by @mattt. +- Fixed inclusion of non-public subclasses of public superclasses. + #131 by @MattKiazyk. ## [1.0.0-beta.3] - 2020-05-19