Commit e879524
Bugfix false positive for "unused" variable for nested
When detecting whether symbols are used or not, variables referenced as argument defaults of the inner def would count as "use" in the inner scope, and hence falsely trigger "unused" warning.
Example:
```
def outer_def(name, foo = "foo"):
def inner_def(foo = foo):
print(foo) # buildifier: disable=print
inner_def()
```
Unused variable check for the above function would
1. Check outer_def for variable usage
2. Recursively check inner_def for variable usage
- Detect that `foo` is used
- Omit `foo` from returned usedSymbolsFromOuterScope since `foo` is a local variable
3. Receive no "usedSymbol" for `foo`
4. Output "unused-variable" warning
If there are RHS idents in a def statement, these idents are always from an outer scope, so these can check the later inner-scope definedSymbols check.
Co-authored-by: Tim Malmström <oreflow@google.com>defs (#1376)1 parent 61dad1f commit e879524
2 files changed
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
413 | 416 | | |
414 | 417 | | |
415 | 418 | | |
| |||
463 | 466 | | |
464 | 467 | | |
465 | 468 | | |
466 | | - | |
| 469 | + | |
| 470 | + | |
467 | 471 | | |
468 | 472 | | |
469 | 473 | | |
| |||
497 | 501 | | |
498 | 502 | | |
499 | 503 | | |
500 | | - | |
501 | 504 | | |
502 | 505 | | |
503 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
668 | 668 | | |
669 | 669 | | |
670 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
671 | 700 | | |
672 | 701 | | |
673 | 702 | | |
| |||
0 commit comments