Skip to content

Conversation

jakitliang
Copy link

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)

@fesily
Copy link
Contributor

fesily commented May 29, 2025

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?

@jakitliang
Copy link
Author

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!

@sumneko sumneko marked this pull request as draft June 9, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants