Skip to content

Commit 68141a0

Browse files
committed
Remove the terminology "l-value" from the diagnostic by being more exact about what sort of lvalue it is.
1 parent 5ed4afe commit 68141a0

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,7 @@ ERROR(expression_unused_closure,none,
28292829
ERROR(expression_unused_function,none,
28302830
"expression resolves to an unused function", ())
28312831
ERROR(expression_unused_lvalue,none,
2832-
"expression resolves to an unused l-value", ())
2832+
"expression resolves to an unused %select{variable|property|subscript}0", (unsigned))
28332833
WARNING(expression_unused_result_call,none,
28342834
"result of call to %0 is unused", (DeclName))
28352835
WARNING(expression_unused_result_operator,none,

lib/Sema/TypeCheckStmt.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,20 @@ void TypeChecker::checkIgnoredExpr(Expr *E) {
10901090

10911091
// Complain about l-values that are neither loaded nor stored.
10921092
if (E->getType()->hasLValueType()) {
1093-
diagnose(E->getLoc(), diag::expression_unused_lvalue)
1093+
// This must stay in sync with diag::expression_unused_lvalue.
1094+
enum {
1095+
SK_Variable = 0,
1096+
SK_Property,
1097+
SK_Subscript
1098+
} storageKind = SK_Variable;
1099+
if (auto declRef = E->getReferencedDecl()) {
1100+
auto decl = declRef.getDecl();
1101+
if (isa<SubscriptDecl>(decl))
1102+
storageKind = SK_Subscript;
1103+
else if (decl->getDeclContext()->isTypeContext())
1104+
storageKind = SK_Property;
1105+
}
1106+
diagnose(E->getLoc(), diag::expression_unused_lvalue, storageKind)
10941107
.highlight(E->getSourceRange());
10951108
return;
10961109
}

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 l-value}}
9+
f // expected-error{{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 l-value}}
15+
a // expected-error{{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
@@ -32,14 +32,14 @@ class D : B {
3232
}
3333

3434
func super_calls() {
35-
super.foo // expected-error {{expression resolves to an unused l-value}}
35+
super.foo // expected-error {{expression resolves to an unused property}}
3636
super.foo.bar // expected-error {{value of type 'Int' has no member 'bar'}}
3737
super.bar // expected-error {{expression resolves to an unused function}}
3838
super.bar()
3939
super.init // expected-error{{'super.init' cannot be called outside of an initializer}}
4040
super.init() // expected-error{{'super.init' cannot be called outside of an initializer}}
4141
super.init(0) // expected-error{{'super.init' cannot be called outside of an initializer}}
42-
super[0] // expected-error {{expression resolves to an unused l-value}}
42+
super[0] // expected-error {{expression resolves to an unused subscript}}
4343
super
4444
.bar()
4545
}

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 l-value}}
24+
var bind_test2 : Int = 4; func1 // expected-error {{expression resolves to an unused variable}}
2525

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

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

0 commit comments

Comments
 (0)