Crash when specifying parameter names in `metamethod __index` function
13k opened this issue · comments
K commented
Using tl stable 0.15.2.
When specifying parameter names in __index
signature, tl crashes:
local record R
metamethod __index: function(self: R, key: string): any
end
function R:brackets()
print(self["x"])
end
function R:dot()
print(self.x)
end
> tl check meta-index.tl
.../lua: .../share/lua/5.4/tl.lua:7528: attempt to index a nil value (field 'e1')
stack traceback:
.../share/lua/5.4/tl.lua:7528: in upvalue 'check_call'
.../share/lua/5.4/tl.lua:7580: in upvalue 'type_check_function_call'
.../share/lua/5.4/tl.lua:7919: in upvalue 'check_metamethod'
.../share/lua/5.4/tl.lua:8008: in upvalue 'type_check_index'
.../share/lua/5.4/tl.lua:9839: in local 'cbkind_after'
.../share/lua/5.4/tl.lua:3610: in upvalue 'recurse'
.../share/lua/5.4/tl.lua:3418: in local 'fn'
.../share/lua/5.4/tl.lua:3602: in upvalue 'recurse'
.../share/lua/5.4/tl.lua:3460: in local 'fn'
.../share/lua/5.4/tl.lua:3602: in upvalue 'recurse'
.../share/lua/5.4/tl.lua:3418: in local 'fn'
.../share/lua/5.4/tl.lua:3602: in upvalue 'recurse'
.../share/lua/5.4/tl.lua:3533: in local 'fn'
.../share/lua/5.4/tl.lua:3602: in upvalue 'recurse'
.../share/lua/5.4/tl.lua:3418: in local 'fn'
.../share/lua/5.4/tl.lua:3602: in function <.../share/lua/5.4/tl.lua:3580>
(...tail calls...)
.../share/lua/5.4/tl.lua:10310: in function 'tl.type_check'
.../share/lua/5.4/tl.lua:10716: in function 'tl.process_string'
(...tail calls...)
.../lib/luarocks/rocks-5.4/tl/0.15.2-1/bin/tl:1181: in field '?'
.../lib/luarocks/rocks-5.4/tl/0.15.2-1/bin/tl:1410: in main chunk
[C]: in ?
After removing the parameter names:
local record R
metamethod __index: function(R, string): any
end
function R:brackets()
print(self["x"])
end
function R:dot()
print(self.x)
end
> tl check meta-index.tl
========================================
Type checked meta-index.tl
0 errors detected
...
Also doesn't matter if using dot-notation or brackets for field access. When using one or the other, or both, crash still happens.
Hisham Muhammad commented
@13k Thank you for the report and testcase!