Skip to content

Commit b263e99

Browse files
Merge pull request #35367 from mininny/simplify-unused-lvalue-wording
[Diagnostics] Simplify unused lvalue warning wording
2 parents 31e460b + 7eaabe1 commit b263e99

File tree

11 files changed

+33
-28
lines changed

11 files changed

+33
-28
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,9 +3785,14 @@ WARNING(guard_always_succeeds,none,
37853785
ERROR(expression_unused_closure,none,
37863786
"closure expression is unused", ())
37873787
ERROR(expression_unused_function,none,
3788-
"expression resolves to an unused function", ())
3788+
"function is unused", ())
37893789
WARNING(expression_unused_lvalue,none,
3790-
"expression resolves to an unused %select{variable|property|subscript}0", (unsigned))
3790+
"%select{"
3791+
"variable|"
3792+
"property is accessed but result|"
3793+
"subscript is accessed but result"
3794+
"}0 is unused",
3795+
(unsigned))
37913796
WARNING(expression_unused_result_call,none,
37923797
"result of call to %0 is unused", (DeclName))
37933798
WARNING(expression_unused_result_operator,none,

test/Constraints/closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func SR3671() {
168168
;
169169

170170
// Also a valid call (!!)
171-
{ $0 { $0 } } { $0 { 1 } } // expected-error {{expression resolves to an unused function}}
171+
{ $0 { $0 } } { $0 { 1 } } // expected-error {{function is unused}}
172172
consume(111)
173173
}
174174

@@ -907,7 +907,7 @@ do {
907907
// The funny error is because we infer the type of badResult as () -> ()
908908
// via the 'T -> U => T -> ()' implicit conversion.
909909
let badResult = { (fn: () -> ()) in fn }
910-
// expected-error@-1 {{expression resolves to an unused function}}
910+
// expected-error@-1 {{function is unused}}
911911

912912
// rdar://problem/55102498 - closure's result type can't be inferred if the last parameter has a default value
913913
func test_trailing_closure_with_defaulted_last() {

test/Parse/consecutive_statements.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ func statement_starts() {
66

77
f(0)
88
f (0)
9-
f // expected-warning{{expression resolves to an unused variable}}
9+
f // expected-warning{{variable is unused}}
1010
(0) // expected-warning {{integer literal is unused}}
1111

1212
var a = [1,2,3]
1313
a[0] = 1
1414
a [0] = 1
15-
a // expected-warning{{expression resolves to an unused variable}}
15+
a // expected-warning{{variable is unused}}
1616
[0, 1, 2] // expected-warning {{expression of type '[Int]' is unused}}
1717
}
1818

test/Parse/super.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class D : B {
3434
}
3535

3636
func super_calls() {
37-
super.foo // expected-warning {{expression resolves to an unused property}}
37+
super.foo // expected-warning {{property is accessed but result is unused}}
3838
super.foo.bar // expected-error {{value of type 'Int' has no member 'bar'}}
39-
super.bar // expected-error {{expression resolves to an unused function}}
39+
super.bar // expected-error {{function is unused}}
4040
super.bar()
4141
// FIXME: should also say "'super.init' cannot be referenced outside of an initializer"
4242
super.init // expected-error{{no exact matches in reference to initializer}}
4343
super.init() // expected-error{{'super.init' cannot be called outside of an initializer}}
4444
super.init(0) // expected-error{{'super.init' cannot be called outside of an initializer}} // expected-error {{missing argument label 'x:' in call}}
45-
super[0] // expected-warning {{expression resolves to an unused subscript}}
45+
super[0] // expected-warning {{subscript is accessed but result is unused}}
4646
super
4747
.bar()
4848
}

test/Parse/toplevel_library_invalid.swift

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

test/SILOptimizer/return.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func testSR13753() {
169169
x // expected-error {{missing return in a closure expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
170170
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
171171
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
172-
// expected-warning@-3 {{expression resolves to an unused variable}}
172+
// expected-warning@-3 {{variable is unused}}
173173
}
174174

175175
func f() -> Int {
@@ -180,7 +180,7 @@ func testSR13753() {
180180
x // expected-error {{missing return in a function expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
181181
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
182182
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
183-
// expected-warning@-3 {{expression resolves to an unused variable}}
183+
// expected-warning@-3 {{variable is unused}}
184184
}
185185

186186
let _ : () -> Int = {
@@ -191,7 +191,7 @@ func testSR13753() {
191191
x
192192
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
193193
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
194-
// expected-warning@-3 {{expression resolves to an unused variable}}
194+
// expected-warning@-3 {{variable is unused}}
195195
} // expected-error {{missing return in a closure expected to return 'Int'}}
196196

197197
func f1() -> Int {
@@ -202,14 +202,14 @@ func testSR13753() {
202202
x
203203
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
204204
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
205-
// expected-warning@-3 {{expression resolves to an unused variable}}
205+
// expected-warning@-3 {{variable is unused}}
206206
} // expected-error {{missing return in a function expected to return 'Int'}}
207207

208208
let _ : () -> Int = {
209209
var x : Int = 0 // expected-warning {{variable 'x' was never mutated; consider changing to 'let' constant}}
210210
var _ : Int = 0
211211

212212
x // expected-error{{missing return in a closure expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
213-
//expected-warning@-1{{expression resolves to an unused variable}}
213+
//expected-warning@-1{{variable is unused}}
214214
}
215215
}

test/attr/attr_discardableResult.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ class Discard {
218218
}
219219

220220
func baz() {
221-
self.bar // expected-error {{expression resolves to an unused function}}
222-
bar // expected-error {{expression resolves to an unused function}}
221+
self.bar // expected-error {{function is unused}}
222+
bar // expected-error {{function is unused}}
223223
}
224224
}
225225

@@ -240,5 +240,5 @@ struct SR_12271_S {
240240
SR_12271_S().bar1() // Okay
241241
SR_12271_S.bar2() // Okay
242242

243-
SR_12271_S().bar1 // expected-error {{expression resolves to an unused function}}
244-
SR_12271_S.bar2 // expected-error {{expression resolves to an unused function}}
243+
SR_12271_S().bar1 // expected-error {{function is unused}}
244+
SR_12271_S.bar2 // expected-error {{function is unused}}

test/decl/enum/enumtest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func test3(_ a: ZeroOneTwoThree) {
7676
ZeroOneTwoThree.Zero // expected-error {{cannot convert value of type 'ZeroOneTwoThree' to specified type 'Int'}}
7777

7878
// expected-warning @+1 {{unused}}
79-
test3 ZeroOneTwoThree.Zero // expected-error {{expression resolves to an unused function}} expected-error{{consecutive statements}} {{8-8=;}}
79+
test3 ZeroOneTwoThree.Zero // expected-error {{function is unused}} expected-error{{consecutive statements}} {{8-8=;}}
8080
test3 (ZeroOneTwoThree.Zero)
8181
test3(ZeroOneTwoThree.Zero)
82-
test3 // expected-error {{expression resolves to an unused function}}
82+
test3 // expected-error {{function is unused}}
8383
// expected-warning @+1 {{unused}}
8484
(ZeroOneTwoThree.Zero)
8585

@@ -101,9 +101,9 @@ func test3a(_ a: ZeroOneTwoThree) {
101101

102102
var i = 0 > 3 ? .none : .some(3) // expected-error {{cannot infer contextual base in reference to member 'none'}}
103103

104-
test3a; // expected-error {{unused function}}
104+
test3a; // expected-error {{function is unused}}
105105
.Zero // expected-error {{reference to member 'Zero' cannot be resolved without a contextual type}}
106-
test3a // expected-error {{unused function}}
106+
test3a // expected-error {{function is unused}}
107107
(.Zero) // expected-error {{reference to member 'Zero' cannot be resolved without a contextual type}}
108108
test3a(.Zero)
109109
}

test/expr/expressions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func1()
2121
_ = 4+7
2222

2323
var bind_test1 : () -> () = func1
24-
var bind_test2 : Int = 4; func1 // expected-warning {{expression resolves to an unused variable}}
24+
var bind_test2 : Int = 4; func1 // expected-warning {{variable is unused}}
2525

26-
(func1, func2) // expected-warning {{expression resolves to an unused variable}}
26+
(func1, func2) // expected-warning {{variable is unused}}
2727

2828
func basictest() {
2929
// Simple integer variables.
@@ -714,7 +714,7 @@ func unusedExpressionResults() {
714714
// <rdar://problem/20749592> Conditional Optional binding hides compiler error
715715
let optionalc:C? = nil
716716
optionalc?.method() // ok
717-
optionalc?.method // expected-error {{expression resolves to an unused function}}
717+
optionalc?.method // expected-error {{function is unused}}
718718
}
719719

720720

test/stmt/yield.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct YieldInDefer {
8585
defer { // expected-warning {{'defer' statement at end of scope always executes immediately}}{{7-12=do}}
8686
// FIXME: this recovery is terrible
8787
yield ""
88-
// expected-error@-1 {{expression resolves to an unused function}}
88+
// expected-error@-1 {{function is unused}}
8989
// expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
9090
// expected-warning@-3 {{string literal is unused}}
9191
}

validation-test/compiler_crashers_2_fixed/sr12994.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ protocol MyProto {
77

88
func compile(x: MyProto) throws {
99
try x.compile
10-
// expected-error@-1 {{expression resolves to an unused function}}
10+
// expected-error@-1 {{function is unused}}
1111
// expected-warning@-2 {{no calls to throwing functions occur within 'try' expression}}
1212
}

0 commit comments

Comments
 (0)