Skip to content

Commit 556be25

Browse files
committed
special treat __*
#2106
1 parent adc1c1b commit 556be25

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

script/vm/compiler.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,8 @@ local compilerSwitch = util.switch()
13411341
hasMarkDoc = vm.bindDocs(source)
13421342
end
13431343

1344+
local key = guide.getKeyName(source)
13441345
if not hasMarkDoc then
1345-
local key = guide.getKeyName(source)
13461346
if key then
13471347
vm.compileByParentNode(source.node, key, function (src)
13481348
if src.type == 'doc.field'
@@ -1368,7 +1368,8 @@ local compilerSwitch = util.switch()
13681368
end
13691369

13701370
if source.value then
1371-
if not hasMarkDoc or source.value.type == 'table' then
1371+
if not hasMarkDoc
1372+
or (type(key) == 'string' and util.stringStartWith(key, '__')) then
13721373
vm.setNode(source, vm.compileNode(source.value))
13731374
end
13741375
end

test/type_inference/init.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,21 @@ local m = setmetatable({},{ __index = { a = 1 } })
42934293
m.<?a?>
42944294
]]
42954295

4296+
TEST 'integer' [[
4297+
---@class metatable : table
4298+
---@field __index table
4299+
4300+
---@param table table
4301+
---@param metatable? metatable
4302+
---@return table
4303+
function setmetatable(table, metatable) end
4304+
4305+
local mt = {a = 1 }
4306+
local m = setmetatable({},{ __index = mt })
4307+
4308+
m.<?a?>
4309+
]]
4310+
42964311
TEST 'integer' [[
42974312
local x = 1
42984313
repeat

0 commit comments

Comments
 (0)