Repository navigation
Conversation
lewis6991
force-pushed
the
rewrite-length-inference
branch
from
October 19, 2026 20:03
9586aca to
c94888d
Compare
lewis6991
force-pushed
the
rewrite-length-inference
branch
from
October 20, 2026 09:59
c94888d to
c7b0ccc
Compare
lewis6991
marked this pull request as draft
October 20, 2026 14:25
Built-in length expressions can keep the operand type. Infer integer for
strings and tables, including aliases and unions. Preserve custom length
operators and the existing fallback for invalid or unresolved operands.
Narrow a[#a] to the element type after a nonempty guard on every path:
---@type string[]
local a = {'first'}
if not a[1] then return end
local last = a[#a] -- string
Limit the proof to direct local tables with no writes, aliases, captures
or escapes anywhere in the function. Check all references once and reuse
the existing flow graph to keep the proof independent of call effects.
Correct constant-index inference so upper bounds keep nil:
if #a <= 1 then local first = a[1] end -- string|nil
Keep equality as a lower-bound proof and handle reversed comparisons.
lewis6991
force-pushed
the
rewrite-length-inference
branch
from
October 21, 2026 10:07
c7b0ccc to
d1fc6e7
Compare
lewis6991
marked this pull request as ready for review
October 21, 2026 10:08
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.
Infer
integerfor built-in string and table lengths through aliases and unions. Preserve customlenoperators and the existing fallback for invalid or unresolved operands.Allow a nonempty guard to prove that
a[#a]has the array's element type:Limit this proof to direct local table literals with no writes, aliases, captures, or escapes anywhere in the function. A guard must hold on every incoming path.
Correct existing constant-index inference so an upper bound alone does not prove an element exists:
Keep equality as a lower-bound proof and handle reversed length comparisons under the same rules.
Related to #886.