Commit 82f3b22
fix: avoid adding parameters for variables defined in the selection during helper extraction (#2373)
Summary:
This PR fixes an issue where the “Extract into helper" functionality incorrectly added variables as parameters to the extracted function when those variables were actually defined inside the selection.
Specifically, variables on the left-hand side of augmented assignments (e.g., `total` in `total += price`) were unconditionally added to the extracted method's parameter list, even if the variable was initialised earlier in the same selection (e.g., `total = 0`).
The fix simply checks `store_refs` for a prior assignment of the variable within the selection before adding it as a parameter.
Fixes #2335
Pull Request resolved: #2373
Test Plan:
1. Added a regression test to cover the changed behaviour.
2. Manual testing:
2.1. Locally built pyrefly to `/some-dir/pyrefly`
2.2. In editor settings, add the following setting: `”pyrefly.lspPath”: ”/some-dir/pyrefly”`
2.3. Manually test the “Extract into helper” functionality to verify fix. See below for reference.
https://github.com/user-attachments/assets/58b18f2a-262b-468b-8f28-1a6e7ee35ebe
Reviewed By: grievejia
Differential Revision: D93156987
Pulled By: kinto0
fbshipit-source-id: b027e9a978a99585349efca736993268eecd81841 parent 84719ad commit 82f3b22
File tree
2 files changed
+66
-2
lines changed- pyrefly/lib
- state/lsp/quick_fixes
- test/lsp
2 files changed
+66
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1486 | 1486 | | |
1487 | 1487 | | |
1488 | 1488 | | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
1489 | 1548 | | |
1490 | 1549 | | |
1491 | 1550 | | |
| |||
0 commit comments