Skip to content

Ignores @available(tvOS, unavailable) and #if os #908

@Ernest0-Production

Description

@Ernest0-Production

Describe the bug

When analyzing the code, it is not taken into account that the target may be cross-platform.
Some functions may not be available or used in one of the platforms.

Reproduction
I tried two options

  1. Active compilation flags
#if os(iOS)
import OtherDeps // ⚠️ import is unused

class OnlyiOSClass { 
}
#endif

For some reason, the index-store continues to receive information about imports wrapped under an inactive compilation flag...

  1. @available keywords
@availalbe(tvOS, unavailable)
class OnlyiOSClass { 
  
   @availalbe(tvOS, unavailable) // ⚠️ init is unused
   init() {}
}

Periphery still sees init in the tvOS index-store. (with clean build)

Workaround

import OtherDeps // ✅ used by OnlyiOSClass

@availalbe(tvOS, unavailable) // ✅ ignored by platform
class OnlyiOSClass {
     
     #if os(iOS) // ✅ ignored by compliation flag
     init() {}
     #endif
}

But this doesn't work if there are uninitialized properties in the class. (compile error)

Environment

periphery version 3.1.0

swift version 6.0

Xcode 16.2
Build version 16C5032a

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