Skip to content

Fix a couple of bugs in type inference - #41

Merged
Tobias-Kohn merged 2 commits into
Tobias-Kohn:masterfrom
neilccbrown:bug-fixes
Jul 25, 2026
Merged

Tobias-Kohn merged 2 commits into
Tobias-Kohn:masterfrom
neilccbrown:bug-fixes

Conversation

@neilccbrown

Copy link
Copy Markdown
Contributor

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's tokenRange lookup (Completer.scala:119) used
an inclusive upper bound, so when the caret sat right before a ) that
closes an enclosing call, that ) got swept into the range. That broke
the length/last-token checks that recognize the (expr).attr pattern, so
completion 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):

myString = "Hello from Strype"

# Controls -- all correctly show string members (e.g. "lower" present, no builtin dump):
wrap(myString.###)                  # no parens, wrapped -> works
("a".upper()).###                   # parens, NOT wrapped -> works
wrap("a".upper().###)               # wrapped, no outer parens -> works

# Broken -- all collapse to a full builtin-name dump instead of the correct members,
# even though the expression before the dot is always well-typed:
wrap((myString).###)                # parens + wrapped, var -> BROKEN
wrap(("a").###)                      # parens + wrapped, string literal -> BROKEN
wrap(("a".upper()).###)              # parens + wrapped, method-call result -> BROKEN

Bug 2 — numeric/boolean/None literals never tracked an end position

AI description: AstNode.Value / AstNode.BooleanValue (int/float/complex/bool/None
literals) never tracked an end position at all, unlike StringValue. So
they couldn't be registered by position in the completion machinery's node
map, and Scope.findName had no case for them either. This broke
(5).attr-style completion even at top level, unwrapped — independent
of the call-wrapping bug above. Fixed by giving both node types a real endPos (BooleanValue computes it
since True/False are fixed-width; Value gets it set from the source
token), and adding a fallback in Scope.findName that delegates to the
existing TypeAstWalker.getType for literal/expression kinds it didn't
special-case.

Original failing example for this (similar to above, but turned out to have a
distinct root cause):

wrap((5).###)                       # parens + wrapped, int literal -> BROKEN

…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.
@Tobias-Kohn
Tobias-Kohn merged commit 045d883 into Tobias-Kohn:master Jul 25, 2026
1 check passed
@neilccbrown
neilccbrown deleted the bug-fixes branch July 25, 2026 07:32
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>
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.

2 participants