swiftlang/swift

[SR-11588] Warn about derived Hashable implementation if there's a custom Equatable

Open

#53.993 aberto em 8 de out. de 2019

Ver no GitHub
 (9 comments) (0 reactions) (1 assignee)Swift (10.719 forks)batch import
compilerderived conformancesgood first issueimprovement

Métricas do repositório

Stars
 (69.989 stars)
Métricas de merge de PR
 (Mesclagem média 8d 17h) (510 fundiu PRs em 30d)

Description

Previous ID SR-11588
Radar rdar://problem/55792988
Original Reporter @beccadax
Type Improvement
Status In Progress
Resolution
Votes 0
Component/s Compiler
Labels Improvement, DerivedConformance, StarterBug
Assignee @JGiola
Priority Medium

md5: 023a941f08cf5b893763b728c33c0c83

relates to:

  • SR-14665 Synthesised Equatable may be incorrect for manually implemented Comparable

Issue Description:

Types that have a custom == almost surely also require a custom Hashable conformance (i.e. the synthesized one will be wrong). Ideally, we wouldn’t synthesize if there’s a custom equatable, but that’s not source-stable. The compiler should emit a warning if it synthesizes a Hashable conformance for a type whose ==(Self, Self) -> Bool implementation is not also synthesized.

This should be relatively simple to do: in the "full Hashable derivation" part of DerivedConformanceEquatableHashable.cpp, after we have decided that we are definitely going to derive an implementation, find the == operator in the type's Equatable conformance and see if it isImplicit(). If it is, emit a warning.

Guia do colaborador