Skip to content

Add sorted-pairs iterator overrides - #6

Merged
Pollux12 merged 1 commit into
Pollux12:betafrom
AmyJeanes:sorted-pairs-iterator-overrides
Jul 26, 2026
Merged

Add sorted-pairs iterator overrides#6
Pollux12 merged 1 commit into
Pollux12:betafrom
AmyJeanes:sorted-pairs-iterator-overrides

Conversation

@AmyJeanes

Copy link
Copy Markdown

SortedPairs, SortedPairsByValue, SortedPairsByMemberValue and RandomPairs scrape to ---@return function, so no types reach their generic-for loop variables. pairs and ipairs already carry the full generic tuple via custom/; this extends the same treatment to the other four.

Only types change — descriptions, @realm and @source are copied verbatim from the current generated output. SortedPairs keeps its single return (it returns a self-contained closure); the other three keep the state return, since they return keyValuePairs, state.

Why it matters

Without a type the loop variable is back-inferred from whatever it gets passed to, so a genuine error inside the loop isn't just missed — it becomes the evidence. The pairs control reports this; the other four accept it:

---@param v Vector
local function takesVector(v) return v end

---@type table<string, string>
local t = { a = "x", b = "y" }

for k in pairs(t) do takesVector(k) end          -- reported
for k in SortedPairs(t) do takesVector(k) end    -- accepted, k back-inferred as Vector

Verification

Whole-repo glua_check 1.1.1 over a 50k-line addon, all three passes on gluals-annotations-prerelease @ 2c8a727e:

annotations suppressions result
current in place clean
current removed 7 × infer-unknown, all sorted-pairs loop variables
this PR removed clean

Retires 7 suppressions with no new diagnostics.

The state-return descriptions match the wiki as it now reads — I corrected those pages first (SortedPairs documented a second return it doesn't have, RandomPairs omitted the one it does, and both SortedPairsBy* described the state record as the source table), so this PR is purely the missing types.

Test added alongside the existing iterator one. Note cli-change-checker.spec.ts and one other suite already fail to compile on main — unrelated to this change.


Disclosure: this was researched and written by Claude Code working in my repositories. Every claim was reproduced and verified against real workspaces rather than asserted, and we went through it together before I raised it. Happy to adjust the shape of the annotations if you'd prefer them written differently.

@AmyJeanes
AmyJeanes force-pushed the sorted-pairs-iterator-overrides branch from 8ce95ee to 40bc9f2 Compare July 26, 2026 16:01
@AmyJeanes
AmyJeanes changed the base branch from main to beta July 26, 2026 16:01
@AmyJeanes

Copy link
Copy Markdown
Author

Retargeted this from main to beta — I'd originally opened it against the default branch without checking which branch feeds which channel. Since gluals-annotations-prerelease is generated from beta, the change needed to land there to reach the prerelease annotations.

The branch is now based on beta rather than main, so the diff is just the five files. The four overrides are unchanged (custom/Global.ipairs.lua is byte-identical on both branches, so the convention they follow is the same either way); the test was rewritten to match beta's custom-annotations.spec.ts, which uses the readCustom helper and toContain.

One caveat on verification: most tests in that file read from output/, which isn't committed and needs a full scrape to produce, so I could only run the new test in isolation (npx jest custom-annotations -t 'sorted-pairs' — passes, the other 16 skip). npx tsc --noEmit -p tsconfig.test.json is clean. Happy to drop the test or reshape it if you'd rather it asserted against the generated output/global.lua like the neighbouring ones.

@Pollux12

Copy link
Copy Markdown
Owner

Don't worry about the failing test, it's unrelated. Thanks for the PR!

@Pollux12
Pollux12 merged commit d4ef897 into Pollux12:beta Jul 26, 2026
1 check failed
@AmyJeanes
AmyJeanes deleted the sorted-pairs-iterator-overrides branch July 27, 2026 09:57
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