Fix a couple of bugs in type inference - #41
Merged
Merged
Conversation
…terals Two independent bugs in dot-completion, both surfacing as a fallback to listing every builtin name instead of the actual type's members: - Completer.getNameFilter used an inclusive token-range bound, so a `)` closing an enclosing call immediately after the caret (e.g. `wrap((expr).<caret>)`) got swept into the range and broke the length/last-token checks that recognize `(expr).attr`. - AstNode.Value/BooleanValue (int/float/complex/bool/None literals) never tracked an end position, unlike StringValue, so they couldn't be registered by position for completion, and Scope.findName had no case for them either. This broke `(5).attr`-style completion even at top level, unrelated to the call-wrapping bug above.
- completer_paren_wrapped_call_var/string_literal/method_result: cover the enclosing-call token-range bug (wrap((expr).<caret>)). - completer_int_literal_unwrapped: covers the missing-endPos bug on its own, at top level with no enclosing call. - completer_paren_wrapped_call_int_literal: end-to-end case combining both fixes, matching the original bug report. Verified each new test fails against the pre-fix code and passes with it.
PwtKCL
pushed a commit
to k-pet-group/Strype
that referenced
this pull request
Jul 27, 2026
…k branch. The published npm package (1.2.2) predates the "Fix a couple of bugs in type inference" PR merged upstream today (Tobias-Kohn/TigerPython-Parser#41, covering the paren-wrapped-call and literal-endPos bugs reported from this branch), and upstream hasn't rebuilt release/ or cut a new version yet. neilccbrown/TigerPython-Parser@test-type-inference has release/ rebuilt from current upstream master, so point at that via a git dependency instead of waiting. Verified: all previously-failing autocomplete.cy.ts cases (the parenthesized-call-wrap dump) now pass, and the full autocomplete/autocomplete-more/autocomplete-graphics-libs suites are green (67/67). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While running our test suite against the new TigerPython version I found two bugs triggered by some of our more awkward test cases that involved brackets around the item before the dot when doing code completion, and were then inside a function call.
Bug 1 — enclosing-call token range off-by-one (the originally reported bug)
AI description:
Completer.getNameFilter'stokenRangelookup (Completer.scala:119) usedan inclusive upper bound, so when the caret sat right before a
)thatcloses an enclosing call, that
)got swept into the range. That brokethe length/last-token checks that recognize the
(expr).attrpattern, socompletion fell through to a full builtin dump. Fixed by excluding tokens starting at or after the caret from that range.
Original failing examples (### marks the completion position, right after the dot):
Bug 2 — numeric/boolean/None literals never tracked an end position
AI description:
AstNode.Value/AstNode.BooleanValue(int/float/complex/bool/Noneliterals) never tracked an end position at all, unlike
StringValue. Sothey couldn't be registered by position in the completion machinery's node
map, and
Scope.findNamehad no case for them either. This broke(5).attr-style completion even at top level, unwrapped — independentof the call-wrapping bug above. Fixed by giving both node types a real
endPos(BooleanValuecomputes itsince
True/Falseare fixed-width;Valuegets it set from the sourcetoken), and adding a fallback in
Scope.findNamethat delegates to theexisting
TypeAstWalker.getTypefor literal/expression kinds it didn'tspecial-case.
Original failing example for this (similar to above, but turned out to have a
distinct root cause):