swiftlang/swift

[SR-5819] Suggest `as? AnyHashable` when `as? Equatable` or `as? Hashable` is attempted

オープン

#48,389 opened on 2017/09/01

 (8 件のコメント) (0 件のリアクション) (0 人の担当者)Swift (10,719 件のフォーク)batch import
bugcompilerdiagnostics qualitygood first issue

Repository metrics

Stars
 (69,989 個のスター)
PR merge metrics
 (平均マージ 8d 17h) (30d で 510 merged PRs)

説明

Previous ID SR-5819
Radar None
Original Reporter @jckarter
Type Bug
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: 5e4ffb6d40f711123adf86651f9a3a8f

Issue Description:

If you have two values of type Any or otherwise opaque type and you want to test whether they're equal, it's natural to try to write something like:

if let a = a as? Equatable, b = b as? Equatable {
  return a == b
}

Maybe someday that will work, but in the meantime dynamically casting to AnyHashable can get the desired effect. It'd be nice QoI to have a diagnostic telling people they can do this when they try similar things that don't.

コントリビューターガイド