Skip to content

[Sema] Translate names in unused result warnings of implicit functions #13622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,18 @@ void TypeChecker::checkIgnoredExpr(Expr *E) {

// Otherwise, produce a generic diagnostic.
if (callee) {
auto &ctx = callee->getASTContext();
if (callee->isImplicit()) {
// Translate calls to implicit functions to their user-facing names
if (callee->getBaseName() == ctx.Id_derived_enum_equals ||
callee->getBaseName() == ctx.Id_derived_struct_equals) {
diagnose(fn->getLoc(), diag::expression_unused_result_operator,
ctx.Id_EqualsOperator)
.highlight(SR1).highlight(SR2);
return;
}
}

auto diagID = diag::expression_unused_result_call;
if (callee->getFullName().isOperator())
diagID = diag::expression_unused_result_operator;
Expand Down
2 changes: 2 additions & 0 deletions test/Sema/enum_equatable_hashable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum Foo {
if Foo.A == .B { }
var aHash: Int = Foo.A.hashValue

Foo.A == Foo.B // expected-warning {{result of operator '==' is unused}}

enum Generic<T> {
case A, B

Expand Down
2 changes: 2 additions & 0 deletions test/Sema/struct_equatable_hashable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct Point: Hashable {
if Point(x: 1, y: 2) == Point(x: 2, y: 1) { }
var pointHash: Int = Point(x: 3, y: 5).hashValue

Point(x: 1, y: 2) == Point(x: 2, y: 1) // expected-warning {{result of operator '==' is unused}}

struct Pair<T: Hashable>: Hashable {
let first: T
let second: T
Expand Down