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-6305] Cannot initialise Dictionary from an EnumeratedSequence #48855

Open
karwa opened this issue Nov 6, 2017 · 4 comments
Open

[SR-6305] Cannot initialise Dictionary from an EnumeratedSequence #48855

karwa opened this issue Nov 6, 2017 · 4 comments
Assignees
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

@karwa
Copy link
Contributor

karwa commented Nov 6, 2017

Previous ID SR-6305
Radar rdar://problem/37159993
Original Reporter @karwa
Type Bug
Environment

Apple Swift version 4.0.3 (swiftlang-900.0.71 clang-900.0.38)

Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @xedin
Priority Medium

md5: a219796b79b304ec98d478ac6a4adc11

is duplicated by:

  • SR-6905 Dictionary(uniqueKeysWithValues:) does not accept sequence of labeled tuples

Issue Description:

The following snippet fails to compile:

let test = Dictionary(uniqueKeysWithValues: ["a", "b", "c"].enumerated())

With the message:

Cannot invoke initializer for type 'Dictionary<_, _>' with an argument list of type '(uniqueKeysWithValues: EnumeratedSequence<[String]>)'

The only way I was able to get it to work was to add a pass-through call to "map" on the end:

let test = Dictionary(uniqueKeysWithValues: ["a", "b", "c"].enumerated().map { $0 })
@belkadan
Copy link
Contributor

belkadan commented Nov 6, 2017

cc @xedin

@belkadan
Copy link
Contributor

belkadan commented Nov 6, 2017

(thanks, Karl!)

@belkadan
Copy link
Contributor

belkadan commented Feb 2, 2018

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by Manuel Martín Benítez (JIRA)

You are just passing a Sequence to the initializer with the keys, and it needs a sequence with key-value pairs.

let test = Dictionary(uniqueKeysWithValues: zip(["a", "b", "c"], [1, 2, 3]))

@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