You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've defined a field as table<MyStates, BaseState>, but the analyzer doesn't complain when I assign a table with a completely different structure to it.
---@classBaseStatelocalBaseState= {}
---@enumMyStateslocalStates= {
GAME=1,
GAME_OVER=2,
}
---@classMyStateMachine---@fieldprivate_states table<MyStates, BaseState>localMyStateMachine= {}
MyStateMachine.__index=MyStateMachine---@paramstatestable<MyStates, BaseState>functionMyStateMachine:setStates(states)
self._states=statesendfunctiontmp()
-- Assigning a table with a different annotation directly. The analyzer doesn't complain.MyStateMachine._states= {
['kek'] =69
}
-- Passing a table with a different annotation to a method. The analyzer doesn't complain.MyStateMachine:setStates({
['kek'] =69,
})
-- The analyzer correctly complains about a number assignment.-- MyStateMachine._states = 69-- The analyzer correctly complains about passing a number.-- MyStateMachine:setStates(2)end
As you can see, the type checker only seems to validate that the value is a table, but doesn't validate the internal key and value types for table<MyStates, BaseState>. Is this the expected behavior, or am I missing something? Is there a way to enforce stricter type checking for the contents of generic tables?
Activity
Dan-Crane commentedon Nov 24, 2025
similar issue: #2610