Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15069] Odd/Possibly incorrect compiler error: requires the types '(key: Choice, value: Int)' and '(Choice, Int)' be equivalent #57395

Open
mattyoung opened this issue Aug 14, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@mattyoung
Copy link

Previous ID SR-15069
Radar rdar://problem/82132819
Original Reporter @mattyoung
Type Bug
Environment

Xcode Version 13.0 beta 5 (13A5212g)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 724739de185acea36e472bb8d15e7473

Issue Description:

I think there should not be any compiler error:

enum Choice: CaseIterable {
    case a, b, c, d, e, f
}

// as show here, the closure can return tuple with any labels
let bitMap = Dictionary<Choice, Int>(uniqueKeysWithValues: Choice.allCases.enumerated().map {
    //    (key: $1, value: 1 << $0)   // error: Initializer 'init(uniqueKeysWithValues:)' requires the types '(key: Choice, value: Int)' and '(Choice, Int)' be equivalent
    //    (key: $1, value: $0)    //  !!! exact same tuple as above, now no problem!
          // not bit shift in second parameter, no problem no matter the tuple labels
    (truck: $1, you: $0)      // no matter what the labels are, all no problem!
    //    ($1, 1 << $0)     // this works
})


// but exactly the same as above, here get compile error
let bitMap2 = Dictionary<Choice, Int>(uniqueKeysWithValues: Choice.allCases.enumerated().map {   // Initializer 'init(uniqueKeysWithValues:)' requires the types '(key: Choice, value: Int)' and '(Choice, Int)' be equivalent
          // bit shift 1 << $0 cause problem
    (key: $1, value: 1 << $0)   // <== because of this, shouldn't be a problem as shown up above
})

// small transform compile fine
let bitMap3 = Dictionary<Choice, Int>(uniqueKeysWithValues: Choice.allCases.enumerated().map {
    let n = 1 << $0
    return (key: $1, value: n)   // <== because of this, shouldn't be a problem as shown up above
})

// also compile
let bitMap4 = Dictionary<Choice, Int>(uniqueKeysWithValues: Choice.allCases.enumerated().map {
    let t = (key: $1, value: 1 << $0)
    return t
})

See: https://forums.swift.org/t/tuple-key-choice-value-int-and-choice-int-not-equivalent/51192/4

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants