Skip to content

impact: file:line inside a method body names that method, though the line assigns a field - #1814

Merged
swapnilpaliwal-sd merged 1 commit into
0.1.9from
fix/fileline-in-body-names-the-method
Sep 30, 2026
Merged

swapnilpaliwal-sd merged 1 commit into
0.1.9from
fix/fileline-in-body-names-the-method

Conversation

@swapnilpaliwal-sd

Copy link
Copy Markdown
Contributor

python/lambda-is-named-by-its-place in the query-layer suite (tests/run.py, which CI does not run) failed one control on 0.1.9. A file:line inside a method body named a field recorded on that line instead of the method:

impact lib.py:3   ->   change: field Orders.items (at lib.py:3)    (the line is `self.items = []` inside Orders.__init__)

A change for JavaScript consts made file:line resolve to a field recorded on that line unless a callable starts on it. Python records self.items = [] as a field of the class, so the field won over the enclosing __init__.

Fix. A new Impact.in_body drops the field when a callable that starts above the line spans it. These do not count as enclosing callables:

  • a module or class body
  • a lambda
  • a field-initializer node
  • a callable holding a local or anonymous type

Module-level constants, class-body fields and the JavaScript const cases resolve as before.

Tests (rebased on the current 0.1.9)

  • lambda-is-named-by-its-place: 35/35 across its four languages.
  • edit-targets-the-declaration-edited: 19/19.
  • called-but-undeclared: 4/4.
  • tests/run.py --lang python: 271/271, against 270/271 before this change.
  • Java: no change. TypeScript and JavaScript: their failures were the same without this change, and are fixed separately.

…line assigns a field

Symptom: `impact lib.py:3` on `self.items = []` inside `Orders.__init__` answered
"field Orders.items" instead of `Orders.__init__` (python/lambda-is-named-by-its-place,
control "file:line inside a method body is still that method").

Cause: field_rows now resolves `file.ext:N` to a field recorded on that line, and the
resolver returns that field unless a callable STARTS on the line. A Python attribute
assigned in a method body is recorded as a field on the assigning line, so the enclosing
method lost to it. G.decl_at_line already refused it; the const-on-the-line branch after
it did not look at enclosing callables.

Fix: drop the field candidate for a file:line when a callable starting above the line
spans it (not a module or class body, not a lambda, not a field-initializer node, and not
through a type declared inside that callable). A field line in a class body or at module
level, and a const whose initializer holds a function, resolve as before.

Tests: python/lambda-is-named-by-its-place 26/26 (25/26 before). tests/run.py --lang
python 271/271 (270/271 before); java 304/304, typescript 181/185, javascript 242/245,
the same failing checks as before the change.

Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
@swapnilpaliwal-sd
swapnilpaliwal-sd merged commit f451375 into 0.1.9 Sep 30, 2026
12 checks passed
@swapnilpaliwal-sd
swapnilpaliwal-sd deleted the fix/fileline-in-body-names-the-method branch September 30, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant