Skip to content

Commit

Permalink
Better fix for inherited generic parameter RPAA false-positive
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Dec 22, 2023
1 parent e2f5fe3 commit 12557c9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions Sources/PeripheryKit/Indexer/Reference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ final class Reference {
case genericRequirementType
case inheritedType
case refinedProtocolType
case conformedType
case initializerType
case variableInitFunctionCall
case functionCallMetatypeArgument
Expand Down
7 changes: 4 additions & 3 deletions Sources/PeripheryKit/Indexer/SwiftIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ public final class SwiftIndexer: Indexer {

for ref in decl.references.union(decl.related) {
if result.inheritedTypeLocations.contains(ref.location) {
if (decl.kind == .class && ref.kind == .class) ||
(decl.kind == .associatedtype && ref.kind == .protocol) {
ref.role = .inheritedType
if decl.kind.isConformableKind, ref.kind == .protocol {
ref.role = .conformedType
} else if decl.kind == .protocol, ref.kind == .protocol {
ref.role = .refinedProtocolType
} else if decl.kind == .class || decl.kind == .associatedtype {
ref.role = .inheritedType
}
} else if result.variableTypeLocations.contains(ref.location) {
ref.role = .varType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ case let .someCase(a, b):
// Inheritance
_ = PublicClassInheritingPublicClass()
_ = PublicClassInheritingPublicExternalClassRetainer()
_ = PublicClassInheritingPublicClassWithGenericParameter()

// Conformance
_ = PublicClassAdoptingPublicProtocol()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

public struct PublicClassInheritingPublicClassWithGenericParameter_GenericType {}
public class PublicClassInheritingPublicClassWithGenericParameter_Superclass<T> {}
public class PublicClassInheritingPublicClassWithGenericParameter: PublicClassInheritingPublicClassWithGenericParameter_Superclass<PublicClassInheritingPublicClassWithGenericParameter_GenericType> {
public override init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class RedundantPublicAccessibilityTest: SourceGraphTestCase {
assertRedundantPublicAccessibility(.class("PublicClassInheritingPublicExternalClass"))
}

func testPublicClassInheritingPublicClassWithGenericRequirement() {
Self.index()

assertNotRedundantPublicAccessibility(.struct("PublicClassInheritingPublicClassWithGenericParameter_GenericType"))
assertNotRedundantPublicAccessibility(.class("PublicClassInheritingPublicClassWithGenericParameter_Superclass"))
assertNotRedundantPublicAccessibility(.class("PublicClassInheritingPublicClassWithGenericParameter"))
}

func testPublicClassAdoptingPublicProtocol() {
Self.index()

Expand Down

0 comments on commit 12557c9

Please sign in to comment.