Skip to content

False positive with computed property defined in enum and called in another target #980

@pylapp

Description

@pylapp

Describe the bug

In my app, I defined an enum with a computed property. This property is used for tests, i.e. is used in another target. periphery sees it as unused, but if the property is removed, the code for tests does not compile.

Maybe it can be related to this issue #831

Reproduction

I have in my app source this enum (source code lighted and annotated, full sources here)

enum TagLayout: CaseIterable, CustomStringConvertible {
    case textOnly
    case textAndBullet
    case textAndIcon

    var description: String {
        switch self {
        case .textOnly:
            "app_components_common_textOnlyLayout_label"
        case .textAndBullet:
            "app_components_tag_textAndBulletLayout_label"
        case .textAndIcon:
            "app_components_common_textAndIconLayout_label"
        }
    }

    var technicalDescription: String { // <--- This is the computed property seen as unused
        switch self {
        case .textOnly:
            "textOnlyLayout"
        case .textAndBullet:
            "textAndBullet"
        case .textAndIcon:
            "textAndIcon"
        }
    }
}

In my test cases, the code is like (source code lighted and annotated, full source code here):

   @MainActor func testTag(theme: OUDSTheme,
                            interfaceStyle: UIUserInterfaceStyle,
                            model: TagConfigurationModel)
    {
        // Generate the illustration for the specified configuration
        let illustration = OUDSThemeableView(theme: theme) {
            TagDemo(configurationModel: model)
                .background(theme.colors.colorBgPrimary.color(for: interfaceStyle == .light ? .light : .dark))
        }

        // Create a unique snapshot name based on the current configuration :
        let testName = "testTag_\(theme.name)Theme_\(interfaceStyle == .light ? "Light" : "Dark")"
        let layoutPattern = model.layout.technicalDescription.localized() // <--- here is the computed property used
        let hierarchyPattern = model.hierarchy.technicalDescription
        let statusPattern = model.status.technicalDescription
        let sizePattern = model.size.technicalDescription
        let shapePattern = model.shape.technicalDescription
        let loaderPattern = model.loader ? "loader" : ""
        let flipIconPattern = model.flipIcon ? "flipIcon" : ""

        let name = "\(layoutPattern)_\(hierarchyPattern)_\(statusPattern)_\(sizePattern)_\(shapePattern)_\(loaderPattern)_\(flipIconPattern)"

        assertIllustration(illustration,
                           on: interfaceStyle,
                           named: name,
                           testName: testName)
    }

Environment

periphery version
3.2.0

swift -version
swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx15.0

xcodebuild -version
Xcode 26.0.1
Build version 17A400

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions