Skip to content

Commit 7aa29b4

Browse files
committed
Add golden tests for unnecessary return check on methods and edge cases
Add test coverage for the unnecessary return check beyond the basic function case: methods with unnecessary return, return-not-at-end (should not warn), and functions without return (should not warn). https://claude.ai/code/session_01868nTfiAXUZdCtDSJshTdu
1 parent 75ab4a3 commit 7aa29b4

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Should warn: unnecessary return at the end of a method.
2+
struct Foo {
3+
x: Int,
4+
}
5+
6+
method get_x(this: Foo): Int {
7+
return this.x
8+
}
9+
10+
// Should not warn: return is not at the end.
11+
fun bar(b: Bool): Int {
12+
if b {
13+
return 1
14+
}
15+
2
16+
}
17+
18+
// Should not warn: no return at the end.
19+
fun baz(): Int {
20+
42
21+
}
22+
23+
// args: check
24+
// expected exit status: 1
25+
// expected stdout:
26+
// Warning: `get_x` is never called.
27+
// --| src/test_files/check/unnecessary_return_method.gdn:6:8
28+
// 4| }
29+
// 5|
30+
// 6| method get_x(this: Foo): Int {
31+
// | ^^^^^
32+
// 7| return this.x
33+
// 8| }
34+
//
35+
// Warning: `bar` is never called.
36+
// --| src/test_files/check/unnecessary_return_method.gdn:11:5
37+
// 10| // Should not warn: return is not at the end.
38+
// 11| fun bar(b: Bool): Int {
39+
// | ^^^
40+
// 12| if b {
41+
// 13| return 1
42+
//
43+
// Warning: `baz` is never called.
44+
// --| src/test_files/check/unnecessary_return_method.gdn:19:5
45+
// 18| // Should not warn: no return at the end.
46+
// 19| fun baz(): Int {
47+
// | ^^^
48+
// 20| 42
49+
// 21| }
50+
//
51+
// Warning: Unnecessary `return` at the end of a function body.
52+
// --| src/test_files/check/unnecessary_return_method.gdn:7:3
53+
// 6| method get_x(this: Foo): Int {
54+
// 7| return this.x
55+
// 8| } ^^^^^^^^^^^^^
56+
57+
// expected stderr:
58+
// 1 issue can be fixed automatically (use `--fix`).
59+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct Foo {
2+
x: Int,
3+
}
4+
5+
method get_x(this: Foo): Int {
6+
return this.x
7+
}
8+
9+
// args: check --fix --stdout
10+
// expected stdout:
11+
// struct Foo {
12+
// x: Int,
13+
// }
14+
//
15+
// method get_x(this: Foo): Int {
16+
// this.x
17+
// }
18+

0 commit comments

Comments
 (0)