Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/SourceGraph/Mutators/UsedDeclarationMarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ final class UsedDeclarationMarker: SourceGraphMutator {
for ref in declaration.related {
markUsed(declarationsReferenced(by: ref))
}

// Follow type references from child property declarations.
// Property type references are associated with the property declaration
// by the indexer, not the containing type. Walking varType references
// ensures types used as property types are marked used when the parent
// type is used.
for childDecl in declaration.declarations where childDecl.kind.isVariableKind {
for ref in childDecl.references where ref.role == .varType {
markUsed(declarationsReferenced(by: ref))
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

struct FixtureItem222: Identifiable, Hashable {
let id: UUID
let name: String
}

public struct FixtureViewModel222 {
struct FixtureSection222: Identifiable, Hashable {
let id: UUID
var equipment: [FixtureItem222]
}
var sections: [FixtureSection222] = []

public mutating func addSection() {
sections.append(FixtureSection222(id: UUID(), equipment: []))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

public class FixtureClassStaticExtMethod {
public func someMethod() {
let _ = [Int].emptyArray()
let _ = [String].constrainedFactory("hello")
NumberFormatter.customFormat()
}
}

extension Array {
static func emptyArray() -> [Any] { [] }
}

extension Array where Element == String {
static func constrainedFactory(_ value: String) -> [String] { [value] }
}

extension NumberFormatter {
static func customFormat() {}
}
26 changes: 25 additions & 1 deletion Tests/PeripheryTests/RetentionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,23 @@ final class RetentionTest: FixtureSourceGraphTestCase {
}
}

func testRetainsStaticMethodOnExternalTypeExtension() {
analyze(retainPublic: true) {
assertReferenced(.class("FixtureClassStaticExtMethod")) {
self.assertReferenced(.functionMethodInstance("someMethod()"))
}
assertReferenced(.extensionStruct("Array", line: 11)) {
self.assertReferenced(.functionMethodStatic("emptyArray()"))
}
assertReferenced(.extensionStruct("Array", line: 15)) {
self.assertReferenced(.functionMethodStatic("constrainedFactory(_:)"))
}
assertReferenced(.extensionClass("NumberFormatter", line: 19)) {
self.assertReferenced(.functionMethodStatic("customFormat()"))
}
}
}

func testRetainsExtendedTypeAlias() {
analyze(retainPublic: true) {
assertReferenced(.typealias("Fixture214TypeAlias"))
Expand Down Expand Up @@ -848,7 +865,14 @@ final class RetentionTest: FixtureSourceGraphTestCase {
assertReferenced(.class("FixtureClass71")) {
self.assertNotReferenced(.varInstance("someVar"))
}
assertNotReferenced(.class("FixtureClass72"))
assertReferenced(.class("FixtureClass72"))
}
}

func testRetainsPropertyTypeReferencesOfUsedDeclaration() {
analyze(retainPublic: true) {
assertReferenced(.struct("FixtureViewModel222"))
assertReferenced(.struct("FixtureItem222"))
}
}

Expand Down
Loading