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-4969] Generic parameter could not be inferred. #47546

Open
swift-ci opened this issue May 23, 2017 · 9 comments
Open

[SR-4969] Generic parameter could not be inferred. #47546

swift-ci opened this issue May 23, 2017 · 9 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4969
Radar rdar://problem/32352586
Original Reporter linqingmo (JIRA User)
Type Bug
Environment

macOS 10.12.5
Xcode 8.3.2
Swift Development Snapshot 2017-05-21 (a)

Additional Detail from JIRA
Votes 2
Component/s Compiler, Standard Library
Labels Bug
Assignee None
Priority Medium

md5: d2daf56b398d2bb6d5c3f3d75f1b03d4

is duplicated by:

  • SR-5274 Generic parameter 'S' could not be inferred when calling merging(_:uniquingKeysWith:) method on Dictionary<String, Any> instance

Issue Description:

There are two function of Dictionary could not use.

public mutating func merge<S>(_ other: S, uniquingKeysWith combine: (Dictionary.Value, Dictionary.Value) throws -> Dictionary.Value) rethrows where S : Sequence, S.Element == (Dictionary.Key, Dictionary.Value)

public func merging<S>(_ other: S, uniquingKeysWith combine: (Dictionary.Value, Dictionary.Value) throws -> Dictionary.Value) rethrows -> [Dictionary.Key : Dictionary.Value] where S : Sequence, S.Element == (Dictionary.Key, Dictionary.Value).

I tried the example, but I encountered a compile bug.
var dictionary = ["a": 1, "b": 2]
dictionary.merge(["a": 3, "c": 4]) { (current, _) in current }

let dictionary = ["a": 1, "b": 2]
let otherDictionary = ["a": 3, "b": 4]
let keepingCurrent = dictionary.merging(otherDictionary) { (current, _) in current }

Generic parameter 'S' could not be inferred.

@belkadan
Copy link
Contributor

@rudkx, @airspeedswift, any idea why there wouldn't be enough type information here?

@airspeedswift
Copy link
Member

+ @natecook1000 who might have seen this before

@rudkx
Copy link
Member

rudkx commented May 23, 2017

@swift-ci create

@ole
Copy link
Contributor

ole commented Jun 5, 2017

This seems to be related to SR-922: the tuple labels of Dictionary's{{Element}} type (key: Key, value: Value) are not compatible with the lable-less tuple format the merge method uses.

@swift-ci
Copy link
Collaborator Author

Comment by Paul Ossenbruggen (JIRA)

Is there a workaround for this?

@airspeedswift
Copy link
Member

Yes - remap the dictionary to be tuple-less e.g.

d1.merge(d2.lazy.map { ($0.key,$0.value) })

Ugly but should work until this is resolved (which is already done on GitHub)

@swift-ci
Copy link
Collaborator Author

Comment by Paul Ossenbruggen (JIRA)

Great! Thanks so much, that worked.

@palimondo
Copy link
Mannequin

palimondo mannequin commented Jun 16, 2017

Ben meant to say "label-less" or unlabeled tuple.

@ole
Copy link
Contributor

ole commented Jul 12, 2017

This seems to be working now (Xcode 9 beta 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 standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

5 participants