Skip to content

Commit 4baf7e3

Browse files
committed
Fix # 50 - Added new rule G-4325: Never reuse labels in inner scopes.
1 parent 60166ce commit 4baf7e3

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# G-4325: Never reuse labels in inner scopes.
2+
3+
!!! warning "Major"
4+
Maintainability, Reliability, Testability
5+
6+
## Reason
7+
8+
Reusing labels inside the scope of another label with the same name leads to confusion, less chance of understanding the code, and could lead to bugs (for example if using `exit my_label` exits at a different nesting level than expected.)
9+
10+
## Example (bad)
11+
12+
``` sql
13+
<<my_label>>
14+
declare
15+
co_min_value constant simple_integer := 1;
16+
co_max_value constant simple_integer := 8;
17+
begin
18+
<<my_label>>
19+
for i in co_min_value..co_max_value
20+
loop
21+
sys.dbms_output.put_line(i);
22+
end loop;
23+
end;
24+
/
25+
```
26+
27+
## Example (good)
28+
29+
``` sql
30+
<<output_values>>
31+
declare
32+
co_min_value constant simple_integer := 1;
33+
co_max_value constant simple_integer := 8;
34+
begin
35+
<<process_values>>
36+
for i in co_min_value..co_max_value
37+
loop
38+
sys.dbms_output.put_line(i);
39+
end loop process_values;
40+
end output_values;
41+
/
42+
```

docs/9-appendix/appendix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ n/a | 4260 | Avoid inverting boolean conditions with NOT. | Minor | | | &#1000
7272
n/a | 4270 | Avoid comparing boolean values to boolean literals. | Minor | | | &#10008; | | | | | &#10008;
7373
39 | 4310 | Never use GOTO statements in your code. | Major | | | &#10008; | | | | | &#10008;
7474
40 | 4320 | Always label your loops. | Minor | | | &#10008; | | | | |
75+
n/a | 4325 | Never reuse labels in inner scopes. | Major | | | &#10008; | | &#10008; | | | &#10008;
7576
41 | 4330 | Always use a CURSOR FOR loop to process the complete cursor results unless you are using bulk operations. | Minor | | | &#10008; | | | | |
7677
42 | 4340 | Always use a NUMERIC FOR loop to process a dense array. | Minor | | | &#10008; | | | | |
7778
43 | 4350 | Always use 1 as lower and COUNT() as upper bound when looping through a dense array. | Major | | | | | &#10008; | | |

0 commit comments

Comments
 (0)