Skip to content

cannot infer table fields when using setmetatable with non-literal table argument #930

@Yuhf7

Description

@Yuhf7

Works:

local tt = setmetatable({ foo = 123, bar = 321 }, {})

-- typing `tt.` shows both 'foo' and 'bar' as suggestions
local a = tt.foo -- `a` is integer

Doesn't work:

local t = { foo = 123, bar = 321 }

local tt = setmetatable(t, {})

-- no suggestions show up when typing `tt.`
local a = tt.foo -- `a` is nil because `tt.foo` is unknown

I first came across this when using emmylua_ls with AwesomeWM and requiring the awful module, but it also occurs in simpler cases like the one above.

In AwesomeWM:

local awful = require('awful')

The only field in awful is a function__index() which isn't even valid.

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