Skip to content

Commit 30faac8

Browse files
committed
SR-11902: Improve Error Message for Auto-synthesized Equatable Conformance on Classes
1. Added note for 'Hashable' and 'Equatable' protocol synthesis for classes.
1 parent be1d896 commit 30faac8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,9 @@ NOTE(missing_member_type_conformance_prevents_synthesis, none,
27102710
"protocol %2, preventing synthesized conformance "
27112711
"of %3 to %2",
27122712
(unsigned, Type, Type, Type))
2713+
NOTE(classes_equatable_hashable_synthesis,none,
2714+
"Currently 'Equatable' and 'Hashable' synthesis is not supported for classes "
2715+
"because of inheritance.", ())
27132716

27142717
// Dynamic Self
27152718
ERROR(dynamic_self_non_method,none,

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ void diagnoseFailedDerivation(DeclContext *DC, NominalTypeDecl *nominal,
165165
nominal->getDeclaredInterfaceType());
166166
}
167167
}
168+
169+
if (auto *classDecl = dyn_cast<ClassDecl>(nominal)) {
170+
ctx.Diags.diagnose(classDecl->getLoc(),
171+
diag::classes_equatable_hashable_synthesis);
172+
}
168173
}
169174

170175
/// Creates a named variable based on a prefix character and a numeric index.

0 commit comments

Comments
 (0)