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-14287] Dictionary(uniqueKeysWithValues:) cannot accept KeyValuePairs #56646

Open
rnapier opened this issue Feb 28, 2021 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@rnapier
Copy link

rnapier commented Feb 28, 2021

Previous ID SR-14287
Radar rdar://problem/74876070
Original Reporter @rnapier
Type Bug
Environment

Xcode 12.5 beta 2

Swift version 5.4 (swiftlang-1205.0.24.6 clang-1205.0.19.54).

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 16f594c0f1d796dd9c1e8bdb575f6220

Issue Description:

KeyValuesPairs is a Sequence whose Element is (key: Key, value: Value). It should be acceptable to Dictionary(uniqueKeysWithValues). Arrays with the same Element are acceptable.

let ps1: [(key: Int, value: String)] = [(1, "1"), (2, "2")]
let ps2: KeyValuePairs<Int, String> = [1: "1", 2: "2"]


type(of: ps1).Element == type(of: ps2).Element // true


let d1 = Dictionary(uniqueKeysWithValues: ps1)
let d2 = Dictionary<Int, String>(uniqueKeysWithValues: ps2) // Initializer 'init(uniqueKeysWithValues:)' requires the types 'KeyValuePairs<Int, String>.Element' (aka '(key: Int, value: String)') and '(Int, String)' be equivalent

This feels like an error in the type checker rather than an error in stdlib.

@typesanitizer
Copy link

@swift-ci create

@lorentey
Copy link
Member

lorentey commented Mar 6, 2021

I suspect the error might be by design here; if so, the pragmatic thing here is probably to add an overload for `uniqueKeysWithValues:`. (Perhaps this can be considered a bugfix, rather than something that needs a proposal.)

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants