Type checker does not respect new/removed metatable

The script editor does not recognize new metatables assigned when you try to overwrite an old metatable with a new one/when you try to get rid of it via setmetatable(t, nil). It keeps the autocomplete info from the first assigned metatable and never updates to reflect new changes.

Repro instructions
Copy and paste this into your script editor and observe the behaviour as outlined by the comments:

local t = setmetatable({}, { __index = { entry = true }})
t.entry --> t.entry autocompletes (as expected)

setmetatable(t, nil)
t.entry --> t.entry still autocompletes

setmetatable(t, { __index = { entry2 = true } })
t.entry --> t.entry autocompletes despite it being overwritten
t.entry2 --> t.entry2 does not autocomplete

Beta features
I have every beta feature enabled except for new studio camera controls and the new topbar

System info
AMD Ryzen 5 5600G with Radeon Graphics
48GB DDR4 RAM @ 3200MHz (47.9 usable)
NVIDIA GeForce RTX 3070Ti

Expected behavior

Autocomplete should recognize when a new metatable replaces an old/existing one.

This is a general feature of our type inference system, which is that we infer all the possible types a value may have. If a variable gets assigned a Foo at one point and a Bar at another, then we will inferFoo|Bar as the type, and provide autocomplete suggestions for both Foo and Bar. We are unlikely to track the imperative state of a variable in its type any time soon.

1 Like

One question, based on what I understand from what you said, wouldn’t this still be unintended behaviour as t.entry2 is not autocompleted? Shouldn’t it allow both t.entry and t.entry2 to be autocompleted?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.