Skip to content

Commit 659e7ce

Browse files
authored
Merge pull request #16059 from AnthonyLatsis/unused-result-closure-warning
[DiagnosticsSema] SR-5983
2 parents a912a12 + ba1bbd0 commit 659e7ce

File tree

11 files changed

+15
-15
lines changed

11 files changed

+15
-15
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,7 @@ WARNING(expression_unused_result_call,none,
29092909
WARNING(expression_unused_result_operator,none,
29102910
"result of operator %0 is unused", (DeclName))
29112911
WARNING(expression_unused_result_unknown, none,
2912-
"result of call is unused, but produces %0", (Type))
2912+
"result of call to %select{function|closure}0 returning %1 is unused", (bool, Type))
29132913
WARNING(expression_unused_result, none,
29142914
"expression of type %0 is unused", (Type))
29152915
WARNING(expression_unused_init_result,none,

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ void TypeChecker::checkIgnoredExpr(Expr *E) {
13221322
.highlight(SR1).highlight(SR2);
13231323
} else
13241324
diagnose(fn->getLoc(), diag::expression_unused_result_unknown,
1325-
valueE->getType())
1325+
isa<ClosureExpr>(fn), valueE->getType())
13261326
.highlight(SR1).highlight(SR2);
13271327

13281328
return;

test/ClangImporter/objc_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func testProtocolMethods(_ b: B, p2m: P2.Type) {
215215

216216
func testId(_ x: AnyObject) {
217217
x.perform!("foo:", with: x) // expected-warning{{no method declared with Objective-C selector 'foo:'}}
218-
// expected-warning @-1 {{result of call is unused, but produces 'Unmanaged<AnyObject>?'}}
218+
// expected-warning @-1 {{result of call to function returning 'Unmanaged<AnyObject>?' is unused}}
219219

220220
_ = x.performAdd(1, withValue: 2, withValue: 3, withValue2: 4)
221221
_ = x.performAdd!(1, withValue: 2, withValue: 3, withValue2: 4)

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ f7(1)(b: 1.0) // expected-error{{extraneous argument label 'b:' in call}}
335335

336336
let f8 = f7(2)
337337
_ = f8(1)
338-
f8(10) // expected-warning {{result of call is unused, but produces 'Int'}}
338+
f8(10) // expected-warning {{result of call to function returning 'Int' is unused}}
339339
f8(1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
340340
f8(b: 1.0) // expected-error {{extraneous argument label 'b:' in call}}
341341

test/Constraints/dynamic_lookup.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ obj.foo!(5)
117117
obj.foo!("hello")
118118
obj.wibble!()
119119
obj.wobble!() // expected-error{{value of type 'Id' (aka 'AnyObject') has no member 'wobble'}}
120-
obj.ext1!() // expected-warning {{result of call is unused}}
120+
obj.ext1!() // expected-warning {{result of call to function returning 'A' is unused}}
121121
obj.wonka!()
122122

123123
// Same as above but without the '!'
@@ -126,7 +126,7 @@ obj.foo(5)
126126
obj.foo("hello")
127127
obj.wibble()
128128
obj.wobble() // expected-error{{value of type 'Id' (aka 'AnyObject') has no member 'wobble'}}
129-
obj.ext1() // expected-warning {{result of call is unused}}
129+
obj.ext1() // expected-warning {{result of call to function returning 'A' is unused}}
130130
obj.wonka()
131131

132132
// Find class methods via dynamic method lookup.
@@ -144,7 +144,7 @@ var ovl1Result = obj.ovl1!()
144144
ovl1Result = A() // verify that we got an A, not a B
145145

146146
// Same as above but without the '!'
147-
obj.ovl1() // expected-warning {{result of call is unused}}
147+
obj.ovl1() // expected-warning {{result of call to function returning 'A' is unused}}
148148

149149
// Don't allow overload resolution between declarations from different
150150
// classes.
@@ -163,7 +163,7 @@ var ovl4Result = obj.ovl4!()
163163
var ovl5Result = obj.ovl5!() // expected-error{{ambiguous use of 'ovl5()'}}
164164

165165
// Same as above but without the '!'
166-
obj.ovl4() // expected-warning {{result of call is unused}}
166+
obj.ovl4() // expected-warning {{result of call to function returning 'B' is unused}}
167167

168168
// Generics
169169

test/Parse/recovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func missingControllingExprInRepeatWhile() {
128128
}
129129

130130
repeat {
131-
} while { true }() // expected-error{{missing condition in a 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{10-10=;}} expected-warning {{result of call is unused, but produces 'Bool'}}
131+
} while { true }() // expected-error{{missing condition in a 'while' statement}} expected-error{{consecutive statements on a line must be separated by ';'}} {{10-10=;}} expected-warning {{result of call to closure returning 'Bool' is unused}}
132132
}
133133

134134
// SR-165

test/Parse/toplevel_library_invalid.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ x + x; // expected-error {{expressions are not allowed at the top level}} expect
77
// Make sure we don't crash on closures at the top level
88
({ }) // expected-error {{expressions are not allowed at the top level}} expected-error{{expression resolves to an unused function}}
99
({ 5 }()) // expected-error {{expressions are not allowed at the top level}}
10-
// expected-warning @-1 {{result of call is unused}}
10+
// expected-warning @-1 {{result of call to closure returning 'Int' is unused}}
1111

1212

1313
// expected-error @+3 {{expected 'in' after for-each pattern}}

test/Parse/try.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct r21432429 {
151151

152152
// <rdar://problem/21427855> Swift 2: Omitting try from call to throwing closure in rethrowing function crashes compiler
153153
func callThrowingClosureWithoutTry(closure: (Int) throws -> Int) rethrows {
154-
closure(0) // expected-error {{call can throw but is not marked with 'try'}} expected-warning {{result of call is unused}}
154+
closure(0) // expected-error {{call can throw but is not marked with 'try'}} expected-warning {{result of call to function returning 'Int' is unused}}
155155
// expected-note@-1 {{did you mean to use 'try'?}} {{3-3=try }}
156156
// expected-note@-2 {{did you mean to handle error as optional value?}} {{3-3=try? }}
157157
// expected-note@-3 {{did you mean to disable error propagation?}} {{3-3=try! }}

test/attr/attr_discardableResult.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func f(a : () -> Int) {
149149
42 // expected-warning {{integer literal is unused}}
150150

151151
4 + 5 // expected-warning {{result of operator '+' is unused}}
152-
a() // expected-warning {{result of call is unused, but produces 'Int'}}
152+
a() // expected-warning {{result of call to function returning 'Int' is unused}}
153153
}
154154

155155
@warn_unused_result func g() -> Int { } // expected-warning {{'warn_unused_result' attribute behavior is now the default}} {{1-21=}}

test/decl/ext/protocol_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OC1 : OP1 {
1616

1717
func testOP1(_ oc1: OC1, ao: AnyObject) {
1818
_ = oc1.extOP1a()
19-
// expected-warning @+1 {{result of call is unused}}
19+
// expected-warning @+1 {{result of call to function returning 'Bool' is unused}}
2020
ao.reqOP1a!() // okay
2121

2222
// Extension of @objc protocol does not have @objc members.

test/expr/expressions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func test_lambda2() {
258258
{ () -> protocol<Int> in
259259
// expected-warning @-1 {{'protocol<...>' composition syntax is deprecated and not needed here}} {{11-24=Int}}
260260
// expected-error @-2 {{non-protocol, non-class type 'Int' cannot be used within a protocol-constrained type}}
261-
// expected-warning @-3 {{result of call is unused}}
261+
// expected-warning @-3 {{result of call to closure returning 'Any' is unused}}
262262
return 1
263263
}()
264264
}
@@ -669,7 +669,7 @@ func lvalue_processing() {
669669

670670
var n = 42
671671
fn(n, 12) // expected-error {{passing value of type 'Int' to an inout parameter requires explicit '&'}} {{6-6=&}}
672-
fn(&n, 12) // expected-warning {{result of call is unused, but produces 'Int'}}
672+
fn(&n, 12) // expected-warning {{result of call to function returning 'Int' is unused}}
673673

674674
n +-+= 12
675675

0 commit comments

Comments
 (0)