Skip to content

Commit

Permalink
Fix public accessibility analysis false-positive for enum case parame…
Browse files Browse the repository at this point in the history
…ter types
  • Loading branch information
ileitch committed Dec 22, 2023
1 parent 12557c9 commit e0647b2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
- Subscript functions required by `@dynamicMemberLookup` are now retained.
- A newline is no longer printed before non-Xcode formatted results.
- `--external-codable-protocols` now retains enums that conform to `CodingKey`.
- Fix redundant public accessibility analysis false-positive for actors.
- Fix redundant public accessibility analysis false-positive for property wrappers.
- Fix redundant public accessibility analysis false-positive for declarations referenced from a public `@inlinable` function.
- Fix redundant public accessibility analysis false-positive for function parameter default values.
- Fix redundant public accessibility analysis false-positive for inherited and default associated types.
- Fix redundant public accessibility analysis false-positive for generic types used in the generic argument clause of a return type.
- Fix redundant public accessibility analysis false-positive for retained/ignored declarations.
- Fix public accessibility analysis false-positive for actors.
- Fix public accessibility analysis false-positive for property wrappers.
- Fix public accessibility analysis false-positive for declarations referenced from a public `@inlinable` function.
- Fix public accessibility analysis false-positive for function parameter default values.
- Fix public accessibility analysis false-positive for inherited and default associated types.
- Fix public accessibility analysis false-positive for generic types used in the generic argument clause of a return type.
- Fix public accessibility analysis false-positive for retained/ignored declarations.
- Fix public accessibility analysis false-positive for enum case parameter types.

## 2.17.1 (2023-12-04)

Expand Down
17 changes: 14 additions & 3 deletions Sources/PeripheryKit/Indexer/SwiftIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,22 @@ public final class SwiftIndexer: Indexer {
.reduce(into: [Int: [Declaration]]()) { (result, decl) in
result[decl.location.line, default: []].append(decl)
}
let sortedDeclLines = declsByLine.keys.sorted().reversed()

for ref in danglingReferences {
guard let candidateDecls =
declsByLocation[ref.location] ??
declsByLine[ref.location.line] else { continue }
let sameLineCandidateDecls = declsByLocation[ref.location] ??
declsByLine[ref.location.line]
var candidateDecls = [Declaration]()

if let sameLineCandidateDecls {
candidateDecls = sameLineCandidateDecls
} else {
// No matching declarations on the same line, default to the nearest preceding
// declaration.
if let line = sortedDeclLines.first(where: { $0 < ref.location.line }) {
candidateDecls = declsByLine[line] ?? []
}
}

// The vast majority of the time there will only be a single declaration for this location,
// however it is possible for there to be more than one. In that case, first attempt to associate with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ case let .someCase(a, b):
_ = a.value
_ = b.value
}
_ = PublicEnumCaseWithParameter.someCase(param1: nil, param2: nil)

// Inheritance
_ = PublicClassInheritingPublicClass()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class PublicEnumCaseWithParameter_ParameterType {}
public class PublicEnumCaseWithParameter_ParameterType_Outer {
public class Inner {}
}
public enum PublicEnumCaseWithParameter {
case someCase(
param1: PublicEnumCaseWithParameter_ParameterType?,
param2: PublicEnumCaseWithParameter_ParameterType_Outer.Inner?
)
}
10 changes: 10 additions & 0 deletions Tests/AccessibilityTests/RedundantPublicAccessibilityTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ class RedundantPublicAccessibilityTest: SourceGraphTestCase {
}
}

func testEnumCaseWithParameter() {
Self.index()

assertNotRedundantPublicAccessibility(.class("PublicEnumCaseWithParameter_ParameterType"))
assertNotRedundantPublicAccessibility(.class("PublicEnumCaseWithParameter_ParameterType_Outer")) {
self.assertNotRedundantPublicAccessibility(.class("Inner"))
}
assertNotRedundantPublicAccessibility(.enum("PublicEnumCaseWithParameter"))
}

func testTypealiasWithClosureType() {
Self.index()

Expand Down

0 comments on commit e0647b2

Please sign in to comment.