Skip to content

Compiler Error: Cannot find type 'CodingKeys' in scope #62106

Open
@garricn

Description

@garricn

Description

Compiler Error: Cannot find type 'CodingKeys' in scope when CodingKeys is used as a parameter in a static or instance method in the main type definition of an Enum.

Steps To Reproduce

  1. Xcode 14.1 playground
  2. This code does NOT compile:
enum SomeCodableEnum: Codable {
    case someCase
    // Compiler Error: "Cannot find type 'CodingKeys' in scope"
    private static func print0(_ codingKeys: CodingKeys.Type) {}
    // Compiler Error: "Cannot find type 'CodingKeys' in scope"
    private func print1(_ codingKeys: CodingKeys.Type) {}
}
  1. This code DOES compile:
enum SomeCodableEnum: Codable {
    case someCase
    static func print0() {
        print(CodingKeys.self)
    }
    func print1() {
        print(CodingKeys.self)
    }
}

extension SomeCodableEnum {
    private static func print2(_ codingKeys: CodingKeys.Type) {
        print(codingKeys)
    }
    private func print3(_ codingKeys: CodingKeys.Type) {
        print(codingKeys)
    }
}

...

Expected behavior
Code should compile when CodingKeys is used as a parameter in the definition of a static or instance method in the main type definition of an Enum.

Environment (please fill out the following information)

  • OS: macOS 12.6.1 (21G217)
  • Xcode Version/Tag/Branch: Xcode 14.1 (14B47B)

Additional context
It appears that structs and classes do not have this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CodableArea → standard library: `Codable` and co.TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesderived conformancesFeature → protocol → conformances: derived conformances aka synthesized conformancestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions