periphery icon indicating copy to clipboard operation
periphery copied to clipboard

Periphery doesn't account for various uses of properties

Open rgoldberg opened this issue 1 month ago • 2 comments

Describe the bug

Periphery doesn't account for various uses of properties.

Reproduction

1: When a property is used as a key for a Dictionary:

import Foundation

struct Thing {
	let path: String
}

let thing = Thing(path: "/dev/null")

var thingByPath = [String:Thing]()
thingByPath[thing.path] = thing

for path in thingByPath.keys {
	do {
		try FileManager.default.attributesOfItem(atPath: path)
		print(1)
	} catch {
		print(2)
	}
}

2: When a property is indirectly used like in an implicit use in String(describing:), either directly or via a call to print(_:separator:terminator:):

struct Thing {
	let id: Int
	let name: String
}

print(Thing(id: 1, name: "a"))

Environment

$ periphery version
3.2.0

$ swift -version
swift-driver version: 1.127.14.1 Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)
Target: arm64-apple-macosx26.0

$ xcodebuild -version
Xcode 26.1.1
Build version 17B100

rgoldberg avatar Dec 05 '25 05:12 rgoldberg

  1. Is a known bug: https://github.com/peripheryapp/periphery/issues/412
  2. This works for me, it correctly reports that both id and name and assigned, but unused. Can you please provide a demo project that reproduces the issue you are seeing?

ileitch avatar Dec 07 '25 18:12 ileitch

Thanks for the info.

In the second case, the properties will be used because print() causes String(describing:) to be called, which uses the values of the properties to generate a String that is printed.

rgoldberg avatar Dec 07 '25 20:12 rgoldberg