Skip to content

A closure param typed by an unresolved name reads fields as nil, so its return mismatches (fork-only; #80 extends it to table literals) #83

Closed

Description

@mareklangiewicz

Corpus hit: snacks.nvim picker/source/lsp/init.lua:452 param-type-mismatch expected { …, filter: (fun(result: lsp.ResultItem) -> boolean)?, … }? but found { …, filter: fun(item: any), … }. It appeared with #80 (97247ef; corpus diff gate-d77de3fe-1121 gate-97247efb-1121). The handoff believed the table literal's closure was losing its return. Closer: the closure does return, a nil. That's because its param is typed with a name that doesn't resolve.

Repro

unresolved_param.lua, as-is (reduced from the snacks file with gndx emmylua reduce … --unless-bin=<gate-d77de3fe-1121>, then by hand):

---@param opts? {filter?:(fun(result:Missing):boolean)}
local function f(opts) return opts end
f({ filter = function(item) return item.kind end })

---@param filter fun(result:Missing):boolean
local function g(filter) return filter end
g(function(item) return item.kind end)
g(function(item) return true end)
return f, g

gndx emmylua probe unresolved_param.lua --bin=~/.cache/gndx/emmylua-corpus/gate-d77de3fe-1121/emmylua_check (bin1 = pre-#80 fork d77de3f):

hit 0.25.1 upstream fork bin1 source
unresolved_param.lua:1 type-not-found Type 'Missing' not found ✓ ✓ ✓ ✓ ---@param opts? {filter?:(fun(result:Missing):boolean)}
unresolved_param.lua:3 param-type-mismatch expected `{ filter: (fun(result: Missing) -> boolean)? }?` but found `{ filter: fun(item: any) }`. ✓ f({ filter = function(item) return item.kind end })
unresolved_param.lua:3 undefined-field Undefined field `kind`. ✓ f({ filter = function(item) return item.kind end })
unresolved_param.lua:3 undefined-field Undefined field: `kind` ✓ f({ filter = function(item) return item.kind end })
unresolved_param.lua:5 type-not-found Type 'Missing' not found ✓ ✓ ✓ ✓ ---@param filter fun(result:Missing):boolean
unresolved_param.lua:7 param-type-mismatch expected `fun(result: Missing) -> boolean` but found `fun(item: unknown)`. ✓ ✓ g(function(item) return item.kind end)
unresolved_param.lua:7 undefined-field Undefined field `kind`. ✓ g(function(item) return item.kind end)
unresolved_param.lua:7 undefined-field Undefined field: `kind` ✓ ✓ g(function(item) return item.kind end)
unresolved_param.lua:8 unused item is never used, if this is intentional, prefix it with an underscore: _item ✓ ✓ ✓ ✓ g(function(item) return true end)

So the table-literal shape (L3) is new with #80. The bare-closure shape (L7) was already fork-only before it.

Why

On every 0.30 build, a field read on an unresolved type infers nil. (---@param m Missing then ---@type fun() local z = m.kind reports found nil on upstream and on the fork.) Upstream doesn't type this closure's item from the expected param (no undefined-field inside the closure on upstream). The fork does, so item: Missing, item.kind: nil, and the closure returns nil against -> boolean. Controls (each one feature changed from L7, all green on every build):

  • return true: the field read is load-bearing (L8 above);
  • fun(result:any):boolean, fun(result:unknown):boolean or fun(result:table):boolean: the unresolved name is load-bearing;
  • fun(result:Missing) (no return annotation): the return check is what reports.

In snacks, lsp.ResultItem = lsp.Symbol|lsp.CallHierarchyItem|{text?:string}. The lsp.* types don't resolve under the corpus's empty config. In a workspace that loads them, this shape doesn't arise. type-not-found already reports the cause.

Proposed: park

The corpus shows this once, only where a type doesn't resolve, and the root cause (a member of an unresolved type is nil, not unknown) is upstream's on every build. Fixing it would change how unresolved names lower, a new concept to remove 1 hit (AGENTS.md "Coarse and sound"). If it shows up in our repos, the Lua-side answer is the missing type or ---@cast.

Activity

  1. mareklangiewicz commented on Nov 22, 2026

    @mareklangiewicz
    OwnerAuthor

    Fixed in 8f00f19 (not pushed yet), but not the way this issue proposed: the "park" premise was wrong. Its root is not upstream design and it is not one hit.

    • Root: a read of an undeclared key returned nil for every Ref/Def owner (vm.rs missing_is_known), though its comment says "declared class instances". A name with no declaration knows nothing about its members; 0.25.1 reads it as unknown, and upstream's own member_missing_in_union already skips such a component. The same rule was wrong for an alias of a union (nil, where the inline union is unknown). New missing_member_is_known: a declared class/enum is known (nil stays), an alias reads like its target, an undeclared name is unknown.
    • Test: test_member_of_an_unresolved_type_is_unknown_not_nil, red → green, with guards (a declared class's and an object alias's missing member stay nil; undefined-field still reports every read). Mutant: making the alias arm answer true goes RED on the two alias reads.
    • Corpus gate-8f00f19a-1122 vs gate-e18788c1-1122 (60/60): +6 −586, net −580 (need-check-nil −483, param-type-mismatch −44, unnecessary-if −31, …). Against v0251-1120 (59 trees): 562 agree, 6 differ. The removed lines are false nil hits wherever lsp.*/uv.* types do not resolve under the corpus's empty config.
    • This issue's corpus hit, snacks lsp/init.lua:452, is still reported. The --unless-bin reduction above slid onto the nearby mechanism. The real one is a whole-literal check that ends Unresolved and is reported as a mismatch; the 6 added lines share it. Filed as A table-literal argument is reported when its check against an expected alias of an unresolved name is Unresolved (fork-only via #80) #84 (proposed park, with the rejected fix and the upstream tests that pin that rule).
    • Gated path: gndx emmylua test 2284 pass, lint PASS, install --with-gate CANDIDATE PASSES (luagnd, myhypr, neospector, config-nvim, ai-lsp CLEAN; corpus 60/60; determinism), installed 0.30.0-main-8f00f19a; gndx gate all PASS, gndx nvim dev check emmylua CLEAN.
  2. mareklangiewicz commented on Nov 22, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream draft PR 1451 opened 2026-11-22, branch fix-missing-member-of-unresolved-type (net vm.rs of 8f00f19 + 4a14dd9, hand-applied to main 70dbcf4; test adapted to main: the two closure cells dropped, since main does not type those closure params; texts_by_code helper added). --red-at=origin/main:…/vm.rs RED -> GREEN; 1982 pass; lint PASS.

    Corpus up-70dbcf4d-1120 → up83-1122: 57387 → 54524 (−2873), much more than on the fork (−580). By code: need-check-nil −2794 (gitsigns −1724, grug-far −444). 2809 of 2828 changed lines agree with v0251-1120. Added: treesitter-context context.lua:219 unnecessary-if (looks true; not on the fork or 0.25.1); #84-shape blink completion.lua:79, oil 600/628, sidekick quickfix.lua:54 (the same as the fork); blink config/sources.lua:80/81 messages vary run to run on the port (1 of 3, then 0 of 4: corpus repeat rep83-1122, rep83b-1122), but not on main (3 of 3 the same, repmain-1122). Stacking upstream PR 1437 did not stop it (rep83s-1122). Not root-caused; the PR body says so.

  3. mareklangiewicz commented on Nov 22, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream 1451: answered the bot review (EmmyLuaLs#1451 (comment)), no code change. Alias cycles (A A, B C/C B) give no hits and no hang on 0.25.1, main, the fork and the port; no source found that reaches the visited guard. Still a draft.

  4. mareklangiewicz commented on Nov 23, 2026

    @mareklangiewicz
    OwnerAuthor

    On the blink.cmp config/sources.lua:76/80/81 lines that varied on the 1451 port: upstream main 48ef52a varies there too. corpus repeat noise48-1123 with 4 runs gives the pattern [1 0 1 1] / [0 1 0 0], so this is main's own run-to-run noise, not something 1451 adds. Measured while re-checking 1448 (#78).

  5. mareklangiewicz commented on Nov 23, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream 1451 body updated 2026-11-23: the blink config/sources.lua caveat now says the variation is main's own noise (4 runs of main 48ef52a, 1 differs). The branch a8b6139 still merges cleanly onto main 48ef52a. Still a draft.

  6. mareklangiewicz commented on Nov 23, 2026

    @mareklangiewicz
    OwnerAuthor

    Re-measured upstream 1451 on main 48ef52a and marked it ready (2026-11-23). Merged main in (1f72bc3, pushed). Tests 1986 + 243 pass; lint PASS. test_member_of_an_unresolved_type_is_unknown_not_nil goes RED → GREEN with --red-at=origin/main:…/vm.rs. Corpus up-48ef52a0-1123 → up83-1123: 57302 → 54436 (−2866); 2812 of the 2831 changed lines agree with 0.25.1. The added lines are the same ones as on 70dbcf4 (the four #84-shape lines, treesitter-context context.lua:219, and main's noise). Body updated. CI green.

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

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions