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-11491] Misleading error message when inserting [T] into Set<T> #53891

Closed
swift-ci opened this issue Sep 19, 2019 · 4 comments
Closed

[SR-11491] Misleading error message when inserting [T] into Set<T> #53891

swift-ci opened this issue Sep 19, 2019 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11491
Radar rdar://problem/55593998
Original Reporter apaszke (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.1 (swiftlang-1100.0.257.2 clang-1100.0.31.3)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee apaszke (JIRA)
Priority Medium

md5: f505094c443eea2740b92e6ff1ed8831

Issue Description:

This code:

let something = ["a"]
var s = Set<String>()
s.insert(something)

produces the following diagnostic:

error.swift:5:3: error: referencing instance method 'insert' on 'Set' requires the types 'String' and 'AnyHashable' be equivalent
s.insert(something)
  ^
Swift.Set<τ_0_0>:1:11: note: where 'Element' = 'String'
extension Set where Element == AnyHashable {
          ^

The error is quite simple – you can't insert a list of elements as an element of a set, but those error messages were confusing enough that it took me some time to find what the error really was. Also IIUC it's not true that `insert` works only if `Element == AnyHashable`, so the message seems false as well.

@theblixguy
Copy link
Collaborator

cc @xedin @hborla

@xedin
Copy link
Member

xedin commented Sep 22, 2019

This is actually pretty interesting because if `s` was indeed a `Set<AnyHashable>` `s.insert(something)` would be a valid call. We produce 2 fixes in this case - one for contextual mismatch between `String` and `Set<String>` as an argument and another one for mismatched requirement for `Element` to be equal to `AnyHashable`, and the latter one wins because it's currently considered as having less of an impact impact. It looks like we should re-evaluate our strategy here and consider fixes for methods from conditional extensions like this much being much heavy.

@xedin
Copy link
Member

xedin commented Sep 22, 2019

@swift-ci create

@xedin
Copy link
Member

xedin commented Oct 1, 2019

Resolved by #27390 apaszke (JIRA User) Please use next available nightly snapshot of master to verify and close.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

3 participants