lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Add support for `getmetatable`

Open jakitliang opened this issue 8 months ago • 2 comments

Show case:

local a = {x = 111}
local mt = {__index = a, __metatable = a, k = 111}
local b = setmetatable({y = 2}, mt)

-- 1. Firstly, giving type info instead of an empty `table`
-- 2. `mt` have `__metatable`, so `c` is `a`
local c = getmetatable(b) 

local mt1 = {__index = a, k = 111}
local d = setmetatable({z = 3}, mt1)

-- 1. Firstly, giving type info instead of an empty `table`
-- 2. `mt1` doesn't have `__metatable`, so `e` is `mt1`
local e = getmetatable(d)

jakitliang avatar May 21 '25 18:05 jakitliang

Please write unittest! I don't have a deep understanding of this, but from a quick look at the code, it seems like you haven't handled this situation.

local a = setmetatable({z = 3}, mt1)
local b = c
local e = getmetatable(b) -- what is e?

fesily avatar May 29 '25 03:05 fesily

Please write unittest! I don't have a deep understanding of this, but from a quick look at the code, it seems like you haven't handled this situation.

local a = setmetatable({z = 3}, mt1)
local b = c
local e = getmetatable(b) -- what is e?

Thanks!

jakitliang avatar May 29 '25 04:05 jakitliang