Skip to content

Commit ebf1b5d

Browse files
Merge pull request swiftlang#35237 from LucianoPAlmeida/SR-13753-stmt
[SR-13753][Diagnostics] Downgrade l-value unused diagnostics to warning
2 parents d6eb325 + 634ce7d commit ebf1b5d

File tree

6 files changed

+63
-9
lines changed

6 files changed

+63
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,8 +3786,8 @@ ERROR(expression_unused_closure,none,
37863786
"closure expression is unused", ())
37873787
ERROR(expression_unused_function,none,
37883788
"expression resolves to an unused function", ())
3789-
ERROR(expression_unused_lvalue,none,
3790-
"expression resolves to an unused %select{variable|property|subscript}0", (unsigned))
3789+
WARNING(expression_unused_lvalue,none,
3790+
"expression resolves to an unused %select{variable|property|subscript}0", (unsigned))
37913791
WARNING(expression_unused_result_call,none,
37923792
"result of call to %0 is unused", (DeclName))
37933793
WARNING(expression_unused_result_operator,none,

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void diagnoseMissingReturn(const UnreachableInst *UI,
6363
if (!BS->empty()) {
6464
auto element = BS->getLastElement();
6565
if (auto expr = element.dyn_cast<Expr *>()) {
66-
if (expr->getType()->isEqual(ResTy)) {
66+
if (expr->getType()->getRValueType()->isEqual(ResTy)) {
6767
Context.Diags.diagnose(
6868
expr->getStartLoc(),
6969
diag::missing_return_last_expr, ResTy,

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-error{{expression resolves to an unused variable}}
9+
f // expected-warning{{expression resolves to an unused variable}}
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-error{{expression resolves to an unused variable}}
15+
a // expected-warning{{expression resolves to an unused variable}}
1616
[0, 1, 2] // expected-warning {{expression of type '[Int]' is unused}}
1717
}
1818

test/Parse/super.swift

Lines changed: 2 additions & 2 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-error {{expression resolves to an unused property}}
37+
super.foo // expected-warning {{expression resolves to an unused property}}
3838
super.foo.bar // expected-error {{value of type 'Int' has no member 'bar'}}
3939
super.bar // expected-error {{expression resolves to an unused function}}
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-error {{expression resolves to an unused subscript}}
45+
super[0] // expected-warning {{expression resolves to an unused subscript}}
4646
super
4747
.bar()
4848
}

test/SILOptimizer/return.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,57 @@ struct StructWithIUOinit : InitProtocol {
159159
init!(_ x: Int) { } // no missing-return error
160160
}
161161

162+
func testSR13753() {
163+
// SR-13753
164+
let _ : () -> Int = {
165+
var x : Int {
166+
get { 0 }
167+
set { }
168+
}
169+
x // expected-error {{missing return in a closure expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
170+
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
171+
// 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}}
173+
}
174+
175+
func f() -> Int {
176+
var x : Int {
177+
get { 0 }
178+
set { }
179+
}
180+
x // expected-error {{missing return in a function expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
181+
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
182+
// 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}}
184+
}
185+
186+
let _ : () -> Int = {
187+
var x : UInt {
188+
get { 0 }
189+
set { }
190+
}
191+
x
192+
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
193+
// 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}}
195+
} // expected-error {{missing return in a closure expected to return 'Int'}}
196+
197+
func f1() -> Int {
198+
var x : UInt {
199+
get { 0 }
200+
set { }
201+
}
202+
x
203+
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
204+
// 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}}
206+
} // expected-error {{missing return in a function expected to return 'Int'}}
207+
208+
let _ : () -> Int = {
209+
var x : Int = 0 // expected-warning {{variable 'x' was never mutated; consider changing to 'let' constant}}
210+
var _ : Int = 0
211+
212+
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}}
214+
}
215+
}

test/expr/expressions.swift

Lines changed: 2 additions & 2 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-error {{expression resolves to an unused variable}}
24+
var bind_test2 : Int = 4; func1 // expected-warning {{expression resolves to an unused variable}}
2525

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

2828
func basictest() {
2929
// Simple integer variables.

0 commit comments

Comments
 (0)