Skip to content

[Feature Request] No HelperCoder generated when check compilation condition #82

Open
@mo5tone

Description

@mo5tone

Describe the bug
Below code works well.

working code
@Codable
@CodedAs<String?>
@CodedAt("operation")
protocol ResponseAttributes {}

@Codable
struct Response {
    @CodedIn("data")
    let id: String
    @CodedIn("data")
    let type: String
    @CodedIn("data")
    @CodedBy(ResponseAttributesCoder())
    let attributes: ResponseAttributes
}

@Codable
struct RegistrationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one("REGISTRATION") }
    let id: String
    @CodedAt("status-code")
    let statusCode: String
    let operation: String
}
@Codable
struct VerificationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one(nil) }
    let id: String
    let operation: String?
    let expiresIn: UInt
    @CodedAt("xxx-token")
    let xxxToken: String
    @CodedAt("yyy-token")
    let yyyToken: String
}

But the ResponseAttributesCoder will be missing if add #if SOME_SWIFT_ACTIVE_COMPILATION_CONDITION.

Xcode say 'Cannot find 'AnonymousAttestationResponseAttributesCoder' in scope'.

failed to work
// Have set the `SOME_SWIFT_ACTIVE_COMPILATION_CONDITION` in `swiftSettings` from `Package.swift`.
#if SOME_SWIFT_ACTIVE_COMPILATION_CONDITION
@Codable
@CodedAs<String?>
@CodedAt("operation")
protocol ResponseAttributes {}

@Codable
struct Response {
    @CodedIn("data")
    let id: String
    @CodedIn("data")
    let type: String
    @CodedIn("data")
    @CodedBy(ResponseAttributesCoder())
    let attributes: ResponseAttributes
}

@Codable
struct RegistrationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one("REGISTRATION") }
    let id: String
    @CodedAt("status-code")
    let statusCode: String
    let operation: String
}
@Codable
struct VerificationAttributes: ResponseAttributes, DynamicCodable {
    static var identifier: DynamicCodableIdentifier<String?> { .one(nil) }
    let id: String
    let operation: String?
    let expiresIn: UInt
    @CodedAt("xxx-token")
    let xxxToken: String
    @CodedAt("yyy-token")
    let yyyToken: String
}
#endif

To Reproduce
Steps to reproduce the behavior:

  1. Create an empty swift package
  2. Add MetaCodable to dependencies
  3. Copy and paste the code above
  4. commnad + B

Expected behavior
Compilation condition check shouldn't fail plugin or macro.

Environment (please complete the following information, remove ones not applicable):

  • OS: macOS
  • Version 13.6.6
  • Xcode 15.2
  • Swift 5.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions