You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A metatable __index function overrides a declared ---@type on main (Neovim's vim.env is "always falsy") #1319
On current main (56267ead, emmylua_check 0.30.0), reading a field of a table declared ---@type table<string, string?> produces the type inferred from its metatable's __index function instead
of the declared value type. That inference can also be wrong. Together they make every if vim.env.X then in Neovim code an unnecessary-if ("always falsy"), because Neovim's runtime declares vim.env exactly this way (runtime/lua/vim/_core/options.lua). 0.25.1 reports nothing.
ifG.envA.Xthenprint'A' end-- main: Impossible `if` statement: this condition is always falsyifG.envD.Xthenprint'D' end-- main: Unnecessary `if` statement: this condition is always truthy
Expected: both are string? (the declared type), so neither if is reported. That is what 0.25.1 does.
Two separate problems seem to be involved:
The declared type loses.envD is declared string?, but reads as string (always truthy). An
explicit ---@type on the table should take precedence over what the metatable's __index returns.
The __index return is inferred as nil.envA's function returns nil on one path and v
(narrowed to string) on the other, which should be string?. It comes out as nil. With return os.getenv(k) the same table reads as string? and nothing is reported.
Controls: setmetatable({}, {}) with no __index, and a plain {}, both keep the declared string?.
Not bisected: 0.25.1 → main crosses the semantic_db rewrite.
Activity