Skip to content

A two-target assign-type-mismatch is reported on either line, run to run #59

Closed

Description

@mareklangiewicz

Part of #17 (corpus diffs need stable reports). The same binary on the same tree reports one assign-type-mismatch on one of two neighbouring lines, varying between runs. Every corpus diff then shows a ±1 "moved" pair that is not a change.

Found while measuring #58 (2026-11-18). Both 0.30.0-main-0a7c4add and 290c77d5, gndx emmylua corpus run … --trees=…:

tree / line variant A variant B observed
nui.nvim lua/nui/tree/init.lua :917 expected integer but found number? :916 expected integer but found number 0a7c4ad: A×3 (incl. own47d-1118), then B×4 in a row; 290c77d: B, A, B, B, B
mason.nvim lua/mason-core/spawn.lua :85 expected IStdioSink but found StdioSink? :86 expected string but found string? 0a7c4ad: A, B, A

nvim-lspconfig lsp/perlls.lua:24 vs :26 moved the same way between own47d-1118 and alias58-1118, but the two binaries agreed on a same-day re-run.

Both sites are a table literal with several mismatching entries (nui: { linenr[1], linenr[2], … }), which suggests the checker reports only the first mismatch found while walking something with no fixed order (a hash map of members or fields?). Not located. Next: reduce one site to a fixture (gndx emmylua reduce) and run emmylua_check on it in a loop to get a fast red repro.

Activity

  1. mareklangiewicz commented on Nov 19, 2026

    @mareklangiewicz
    OwnerAuthor

    Fixed in 29b1a45 (installed 0.30.0-main-29b1a458, gated; not pushed yet).

    Cause. check_table_record (semantic_model/type_check/simple_type.rs) walked the target record's fields in hashbrown::HashMap order, and check_all stops at the first failure. add_mismatch then puts the diagnostic on that field's entry. foldhash seeds every map anew (gen_per_hasher_seed), so the "first" mismatching field differed from one run to the next, and even between maps in one process. Class targets take the same path (class_fields → LuaObjectType), so ---@type C literals flipped too.

    Fix. The fields are walked in LuaMemberKey order (integers ascending, then names). A literal with several mismatching entries is still reported once, at the lowest key.

    Red loop (before the fix, 290c77d, 30 runs each):

    fixture lines reported
    { [1]: integer, [2]: integer } ← { a, b } (number, number?) 8 ×15, 9 ×5
    3-tuple object, three number entries 6 ×11, 7 ×8, 8 ×11
    ---@class P x/y/z, three number entries 10 ×11, 11 ×9, 12 ×10
    one mismatching entry (control) 6 ×30

    After: each fixture reports one line, 30/30.

    Test. test_record_mismatch_reports_the_same_entry_every_run runs 16 fresh databases per target shape (object and class). --red-revert=HEAD: RED ({10, 11, 12}) → GREEN. Full suite 2238 pass. Lint, gndx emmylua gate, gndx gate all and gndx nvim dev check emmylua pass.

    Corpus. base290-1119 (290c77d) → fix59-1119 (29b1a45): totals 57209 → 57209. The one changed line is mason spawn.lua:85 → :86, which is this flip. On the fix, 4 runs (mfix59-<n>-1119) of mason, nui and lspconfig agree: nui tree/init.lua:916, mason spawn.lua:86, lspconfig perlls.lua:26.

    Not covered: check_union_intersection_source (type_check/mod.rs, the intersection-source arm) also walks object.get_fields() in hash order. It yields only a reason, with no field location, so it can't move a line. At most it could vary the reason text. Not observed; left alone.

  2. mareklangiewicz commented on Nov 19, 2026

    @mareklangiewicz
    OwnerAuthor

    Pushed 29b1a45 to marek-main-fixes. Upstream PR next (draft).

  3. mareklangiewicz commented on Nov 19, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream draft: upstream EmmyLuaLs#1437 (branch fix-record-field-order, 4f031f1 on upstream main 280987f). On upstream main, the same 4 trees over 3 runs vary by 108–135 report lines in 32 files. With the fix, 0–5 lines in one file (blink.cmp config/sources.lua, where the literal's inferred type itself changes: an upstream-only source; the fork reports nothing there, 4/4 runs). Upstream main also crashes (stack overflow) on async.nvim, bufferline.nvim, neotest, neovim-runtime and tuis.nvim, with and without the fix.

  4. added 2 commits that reference this issue on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions