Skip to content

Commit 243d03d

Browse files
committed
Diagnose named-but-unused local variables
This is a case of losing a non-discarded value that wasn't being covered with the discarding rule. I think I like this... although I had to update unused dummy variables in the tests to rename them to `_`, it caught a few cases where I had a loop `counter` variable I wasn't actually using that was just a leftover from a previous incarnation of the test, so I could and did remove it.
1 parent 70f8506 commit 243d03d

29 files changed

+121
-79
lines changed

regression-tests/mixed-lifetime-safety-pointer-init-1-error.cpp2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ main: () -> int = {
1515
}
1616

1717
print_and_decorate( p* );
18+
print_and_decorate( x );
1819
}
1920

20-
print_and_decorate: (thing:_) =
21+
print_and_decorate: (thing) =
2122
std::cout << ">> " << thing << "\n";
2223

regression-tests/mixed-lifetime-safety-pointer-init-2-error.cpp2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ main: () -> int = {
1515
}
1616

1717
print_and_decorate( p* );
18+
print_and_decorate( x );
1819
}
1920

20-
print_and_decorate: (thing:_) =
21+
print_and_decorate: (thing) =
2122
std::cout << ">> " << thing << "\n";
2223

regression-tests/mixed-lifetime-safety-pointer-init-3-error.cpp2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ main: () -> int = {
1515
}
1616

1717
print_and_decorate( p* );
18+
print_and_decorate( x );
1819
}
1920

20-
print_and_decorate: (thing:_) =
21+
print_and_decorate: (thing) =
2122
std::cout << ">> " << thing << "\n";
2223

regression-tests/mixed-out-destruction.cpp2

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ struct C {
1919

2020
//-------------------------------------------------------
2121
// 0x: Test one level of out and immediate throw
22-
f00: () throws = { c:C="f00"; x: X; f01(out x); }
23-
f01: (out x: X) throws = { c:C="f01"; x=(); throw_1(); }
22+
f00: () throws = { _:C="f00"; x: X; f01(out x); }
23+
f01: (out x: X) throws = { _:C="f01"; x=(); throw_1(); }
2424

2525
//-------------------------------------------------------
2626
// 1x: Test multiple levels of out and intermediate throw
27-
f10: () throws = { c:C="f10"; x: X; f11(out x); }
28-
f11: (out x: X) throws = { c:C="f11"; f12(out x); }
29-
f12: (out x: X) throws = { c:C="f12"; f13(out x); throw_1(); }
30-
f13: (out x: X) throws = { c:C="f13"; f14(out x); }
31-
f14: (out x: X) throws = { c:C="f14"; x=(); }
27+
f10: () throws = { _:C="f10"; x: X; f11(out x); }
28+
f11: (out x: X) throws = { _:C="f11"; f12(out x); }
29+
f12: (out x: X) throws = { _:C="f12"; f13(out x); throw_1(); }
30+
f13: (out x: X) throws = { _:C="f13"; f14(out x); }
31+
f14: (out x: X) throws = { _:C="f14"; x=(); }
3232

3333
int main() {
3434
C c("main");

regression-tests/pure2-break-continue.cpp2

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ do_break_outer: () =
160160
for_continue_inner: () =
161161
{
162162
vi: std::vector = ( 0, 1, 2 );
163-
counter := 0;
164-
for vi next counter++ do (i) {
163+
for vi do (i) {
165164
vj: std::vector = ( 0, 1, 2 );
166165
inner: for vj do (j) {
167166
std::cout << i << j << " ";
@@ -178,8 +177,7 @@ for_continue_inner: () =
178177
for_continue_outer: () =
179178
{
180179
vi: std::vector = ( 0, 1, 2 );
181-
counter := 0;
182-
outer: for vi next counter++ do (i) {
180+
outer: for vi do (i) {
183181
vj: std::vector = ( 0, 1, 2 );
184182
for vj do (j) {
185183
std::cout << i << j << " ";
@@ -196,8 +194,7 @@ for_continue_outer: () =
196194
for_break_inner: () =
197195
{
198196
vi: std::vector = ( 0, 1, 2 );
199-
counter := 0;
200-
for vi next counter++ do (i) {
197+
for vi do (i) {
201198
vj: std::vector = ( 0, 1, 2 );
202199
inner: for vj do (j) {
203200
std::cout << i << j << " ";
@@ -214,8 +211,7 @@ for_break_inner: () =
214211
for_break_outer: () =
215212
{
216213
vi: std::vector = ( 0, 1, 2 );
217-
counter := 0;
218-
outer: for vi next counter++ do (i) {
214+
outer: for vi do (i) {
219215
vj: std::vector = ( 0, 1, 2 );
220216
for vj do (j) {
221217
std::cout << i << j << " ";

regression-tests/pure2-deducing-pointers-error.cpp2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ main: () -> int = {
3838
fp = 0; // caught
3939

4040
f := fun(a)*;
41+
_ = f;
4142

4243
fp2 := fun2(a).result;
4344
fp2--; // not caught :(

regression-tests/pure2-lifetime-safety-pointer-init-1-error.cpp2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ main: () -> int = {
1212
}
1313

1414
print_and_decorate( p* );
15+
print_and_decorate( x );
1516
}
1617

17-
print_and_decorate: (thing:_) =
18+
print_and_decorate: (thing) =
1819
std::cout << ">> " << thing << "\n";
1920

regression-tests/pure2-look-up-parameter-across-unnamed-function.cpp2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
f: () -> (ri : int = 0) = {
33
pred := :(e) e == 1;
44
ri = 42;
5+
pred(ri);
56
// "return;" is implicit"
67
}
78

89
g: () -> (ri : int) = {
910
ri = 0;
1011
pred := :(e) e == 1;
1112
ri = 42;
13+
pred(ri);
1214
return;
1315
}
1416

regression-tests/pure2-more-wildcards.cpp2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ main: () -> int
66
x: const _ = 2;
77
p: * _ = x&;
88
q: * const _ = p&;
9+
assert (q);
910

1011
if x is (less_than(20)) {
1112
std::cout << "yes, less\n";

regression-tests/pure2-requires-clauses.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ f: <T: type, U: type>
1818
v: <T> const T requires std::same_as<T, i32> = 0;
1919

2020
main: () = {
21-
x: X<int,int> = ();
21+
_: X<int,int> = ();
2222
std::cout << f<int,int>(2,5);
2323
}

0 commit comments

Comments
 (0)