Skip to content

Compile error when trying to use variadic generics for KeyPath #66125

Closed
@mateusrodriguesxyz

Description

@mateusrodriguesxyz

Description

I can't make the following code compile:

struct T {
    var p1: String
    var p2: Int
    var p3: Double
}

extension Array {
    
    func f<each P: Comparable>(_ keyPath: repeat KeyPath<Self.Element, each P>) {
//        repeat print(each keyPath) // Type of expression is ambiguous without more context
    }
    
}

let ts: [T] = []

ts.f(\.p1, \.p2, \.p3)

Steps to reproduce

Run the code above using the 2023-05-22 Snapshot

Expected behavior

print \T.p1 \T.p2 \T.p3

Environment

  • Swift compiler version info: 2023-05-22 Snapshot
  • Xcode version info: Xcode 14.3 Build version 14E222b
  • Deployment target: macOS 13.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.parameter packsFeature → generics: Parameter packstype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions