Skip to content

Commit fbea78a

Browse files
authored
Merge pull request #13622 from ahoppen/unused-result-implicit-funcs
2 parents 291e550 + 8d3652a commit fbea78a

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,18 @@ void TypeChecker::checkIgnoredExpr(Expr *E) {
12011201

12021202
// Otherwise, produce a generic diagnostic.
12031203
if (callee) {
1204+
auto &ctx = callee->getASTContext();
1205+
if (callee->isImplicit()) {
1206+
// Translate calls to implicit functions to their user-facing names
1207+
if (callee->getBaseName() == ctx.Id_derived_enum_equals ||
1208+
callee->getBaseName() == ctx.Id_derived_struct_equals) {
1209+
diagnose(fn->getLoc(), diag::expression_unused_result_operator,
1210+
ctx.Id_EqualsOperator)
1211+
.highlight(SR1).highlight(SR2);
1212+
return;
1213+
}
1214+
}
1215+
12041216
auto diagID = diag::expression_unused_result_call;
12051217
if (callee->getFullName().isOperator())
12061218
diagID = diag::expression_unused_result_operator;

test/Sema/enum_equatable_hashable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ enum Foo {
99
if Foo.A == .B { }
1010
var aHash: Int = Foo.A.hashValue
1111

12+
Foo.A == Foo.B // expected-warning {{result of operator '==' is unused}}
13+
1214
enum Generic<T> {
1315
case A, B
1416

test/Sema/struct_equatable_hashable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct Point: Hashable {
1010
if Point(x: 1, y: 2) == Point(x: 2, y: 1) { }
1111
var pointHash: Int = Point(x: 3, y: 5).hashValue
1212

13+
Point(x: 1, y: 2) == Point(x: 2, y: 1) // expected-warning {{result of operator '==' is unused}}
14+
1315
struct Pair<T: Hashable>: Hashable {
1416
let first: T
1517
let second: T

0 commit comments

Comments
 (0)