Skip to content

Regression on main: indexing table<string, V> gives unknown instead of V #1334

Open

Description

@mareklangiewicz

Repro

---@param pt table<string, integer>
---@param k string
local function g(pt, k)
  ---@type boolean
  local a = pt.X     -- 0.25.1: Cannot assign `integer` to `boolean`
  ---@type boolean
  local c = pt[k]    -- 0.25.1: Cannot assign `integer` to `boolean`
  local u = pt.X.y   -- 0.25.1: Undefined field `y`
  local v = pt.X()   -- 0.25.1: Cannot call expression of type `integer`
  return a, c, u, v
end

---@type integer
local i = 1
---@type boolean
local ctl = i        -- control: warns on both
return g, ctl

emmylua_check on 0.25.1 reports all four lines in g. On main (56267ead, 0.30.0) it reports only the control line. An index read of table<string, V> behaves as unknown: no assignment or argument mismatch, and indexing or calling it is allowed. It is the same for pt.X, pt['X'] and pt[k], for a parameter, and for a local typed with ---@type table<string, integer> (with or without an initializer).

Impact

Every table<string, V> read loses its type. With #1319 fixed, vim.env.X (---@type table<string, string?>) reads as unknown instead of string?.

Written with help from Claude Code.

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