Skip to content

Commit 77a0763

Browse files
authored
Fix redundant public accessibility analysis for types used in closure signatures. Closes #522 (#542)
1 parent 595e24f commit 77a0763

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Fix unused parameter analysis for shorthand if-let syntax.
1515
- Workaround Swift shorthand if-let syntax bug (https://github.com/apple/swift/issues/61509). Global properties are not handled by this workaround.
1616
- Fix retaining inferred associated types.
17+
- Fix redundant public accessibility analysis for types used in closure signatures.
1718

1819
## 2.10.0 (2022-10-10)
1920

Sources/PeripheryKit/Syntax/DeclarationVisitor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,15 @@ final class DeclarationVisitor: PeripherySyntaxVisitor {
171171
func visitPost(_ node: VariableDeclSyntax) {
172172
for binding in node.bindings {
173173
if binding.pattern.is(IdentifierPatternSyntax.self) {
174+
let closureSignature = binding.initializer?.value.as(ClosureExprSyntax.self)?.signature
175+
let closureParameters = closureSignature?.input?.as(ParameterClauseSyntax.self)
174176
parse(
175177
modifiers: node.modifiers,
176178
attributes: node.attributes,
177179
trivia: node.leadingTrivia,
178180
variableType: binding.typeAnnotation?.type,
181+
parameterClause: closureParameters,
182+
returnClause: closureSignature?.output,
179183
at: binding.positionAfterSkippingLeadingTrivia
180184
)
181185
} else if let tuplePatternSyntax = binding.pattern.as(TuplePatternSyntax.self) {

Tests/AccessibilityTests/AccessibilityProject/Sources/MainTarget/main.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ _ = InternalClassAdoptingPublicProtocolRetainer()
5454
let _: PublicProtocolRefiningPublicProtocol? = nil
5555
_ = InternalProtocolRefiningPublicProtocolRetainer()
5656

57+
// Closure
58+
let _ = PublicTypeUsedInPublicClosureRetainer().closure
59+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
3+
public class PublicTypeUsedInPublicClosureReturnType {}
4+
public class PublicTypeUsedInPublicClosureInputType {}
5+
6+
public class PublicTypeUsedInPublicClosureRetainer {
7+
public var closure = { (a: PublicTypeUsedInPublicClosureInputType) -> PublicTypeUsedInPublicClosureReturnType in
8+
PublicTypeUsedInPublicClosureReturnType()
9+
}
10+
public init() {}
11+
}

Tests/AccessibilityTests/RedundantPublicAccessibilityTest.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,9 @@ class RedundantPublicAccessibilityTest: SourceGraphTestCase {
148148
assertNotRedundantPublicAccessibility(.typealias("PublicTypealiasWithClosureType"))
149149
assertNotRedundantPublicAccessibility(.struct("PublicTypealiasStruct"))
150150
}
151+
152+
func testPublicTypeUsedInPublicClosure() {
153+
assertNotRedundantPublicAccessibility(.class("PublicTypeUsedInPublicClosureReturnType"))
154+
assertNotRedundantPublicAccessibility(.class("PublicTypeUsedInPublicClosureInputType"))
155+
}
151156
}

0 commit comments

Comments
 (0)