-
-
Notifications
You must be signed in to change notification settings - Fork 220
Closed
Labels
needs investigationBug report that needs confirmationBug report that needs confirmation
Description
Describe the bug
Periphery incorrectly reports subscript(dynamicMember:) as unused when extending AttributeDynamicLookup to support custom AttributeScope types.
When defining a custom AttributeScope and the corresponding AttributeDynamicLookup subscript (as documented by Apple for extending AttributedString), periphery reports:
warning: Unused function 'subscript(dynamicMember:)'
However, removing this subscript causes compilation to fail because self.myAttribute cannot be resolved on AttributeContainer.
Reproduction
import Foundation
// Custom attribute key
enum MyAttribute: AttributedStringKey {
typealias Value = String
static let name = "MyAttribute"
}
// Custom attribute scope - periphery reports this as unused
extension AttributeScopes {
struct CustomAttributes: AttributeScope {
let myAttribute: MyAttribute
}
}
// Dynamic member lookup subscript - periphery reports this as unused
extension AttributeDynamicLookup {
subscript<T: AttributedStringKey>(
dynamicMember keyPath: KeyPath<AttributeScopes.CustomAttributes, T>
) -> T {
self[T.self]
}
}
// Extension that uses the custom attribute via dynamic member lookup
extension AttributeContainer {
var customValue: String? {
get { self.myAttribute } // This requires the subscript and scope above
set { self.myAttribute = newValue }
}
}
// Main entry point
@main
struct Main {
static func main() {
var container = AttributeContainer()
container.customValue = "hello"
print(container.customValue ?? "nil")
}
}
Output:
/private/tmp/periphery-false-positive/Sources/PeripheryFalsePositive/PeripheryFalsePositive.swift:18:5: warning: Unused function 'subscript(dynamicMember:)'
Environment
Copy the output from running:
3.4.0
swift-driver version: 1.127.14.1 Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
Target: arm64-apple-macosx26.0
Xcode 26.2
Build version 17C52
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
needs investigationBug report that needs confirmationBug report that needs confirmation