Skip to content

Commit aebe2ab

Browse files
committed
Fix missing operators in synthesized == impls printed by -print-ast.
`visitBinaryExpr` wasn't handling `UnresolvedDeclRefExpr` nodes, which the synthesized `==` implementation uses to compare fields/payloads. Also fixed the test that wasn't catching it since it also left out the operators.
1 parent fb259ea commit aebe2ab

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,6 +4792,10 @@ void PrintAST::visitBinaryExpr(BinaryExpr *expr) {
47924792
Printer << operatorRef->getDecl()->getBaseName();
47934793
} else if (auto *operatorRef = dyn_cast<DeclRefExpr>(expr->getFn())) {
47944794
Printer << operatorRef->getDecl()->getBaseName();
4795+
} else if (auto *operatorRef =
4796+
dyn_cast<UnresolvedDeclRefExpr>(expr->getFn())) {
4797+
// Synthesized `==` uses this.
4798+
Printer << operatorRef->getName();
47954799
}
47964800
Printer << " ";
47974801
visit(expr->getRHS());

test/decl/enum/derived_hashable_equatable.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ enum HasAssociatedValues: Hashable {
6868
// CHECK: @_implements(Equatable, ==(_:_:)) internal static func __derived_enum_equals(_ a: HasAssociatedValues, _ b: HasAssociatedValues) -> Bool {
6969
// CHECK-NEXT: switch (a, b) {
7070
// CHECK-NEXT: case (.a(let l0), .a(let r0)):
71-
// CHECK-NEXT: guard l0 r0 else {
71+
// CHECK-NEXT: guard l0 == r0 else {
7272
// CHECK-NEXT: return false
7373
// CHECK-NEXT: }
7474
// CHECK-NEXT: return true
7575
// CHECK-NEXT: case (.b(let l0), .b(let r0)):
76-
// CHECK-NEXT: guard l0 r0 else {
76+
// CHECK-NEXT: guard l0 == r0 else {
7777
// CHECK-NEXT: return false
7878
// CHECK-NEXT: }
7979
// CHECK-NEXT: return true
@@ -158,7 +158,7 @@ enum HasAssociatedValuesAndUnavailableElement: Hashable {
158158
// CHECK: @_implements(Equatable, ==(_:_:)) internal static func __derived_enum_equals(_ a: HasAssociatedValuesAndUnavailableElement, _ b: HasAssociatedValuesAndUnavailableElement) -> Bool {
159159
// CHECK-NEXT: switch (a, b) {
160160
// CHECK-NEXT: case (.a(let l0), .a(let r0)):
161-
// CHECK-NEXT: guard l0 r0 else {
161+
// CHECK-NEXT: guard l0 == r0 else {
162162
// CHECK-NEXT: return false
163163
// CHECK-NEXT: }
164164
// CHECK-NEXT: return true

0 commit comments

Comments
 (0)