Intellisense incorrectly warnings when indexing metatable types with generic typing when accessed from iterating through tables

I am not using the new Luau Type Solver!

Storing metatable types with generics in tables, then iterating through them and running them, produces a false type warning. For example:

--!strict

local SomeGenericClass = {}
SomeGenericClass.__index = SomeGenericClass

type SomeGenericClass<Class> = typeof(setmetatable({}:: {
	_Object: Class,
}, SomeGenericClass))

function SomeGenericClass.SomeGenericMethod<Class>(self: SomeGenericClass<Class>)
	self:SomeGenericMethod()
end

----------------------------------------------------------------------------------------------------
-->> warning
local arrayWithGenericClass: {SomeGenericClass<Frame>} = {}
for _, Class in arrayWithGenericClass do
	Class:SomeGenericMethod() --> warns (warning below)
	--[[
		Type Error: Type 'SomeGenericClass' could not be converted into
		'SomeGenericClass' caused by: Type 'SomeGenericClass' from
		'game.Workspace.Script' could not be converted into'SomeGenericClass'
		from 'game.Workspace.Script' caused by: Property 'SomeGenericMethod'
		is not compatible. Type '(SomeGenericClass) -> ()' could not be
		converted into '<Class>(SomeGenericClass) -> ()'; different number
		of generic type parameters
	]]
end

-->> no warning
local ExplicitDefinition: SomeGenericClass<Frame> = setmetatable({
	_Object = Instance.new("Frame"),
}, SomeGenericClass)
ExplicitDefinition:SomeGenericMethod() --> accessing explicit definitions are fine
arrayWithGenericClass[1]:SomeGenericMethod() --> accessing using indexing is fine
----------------------------------------------------------------------------------------------------

Expected behavior

No warning, since it’s a valid action.

Thank you for the report.

This issue has been fixed in the new Luau type solver.
We are not making improvements to the old solver any more, unless it is a bug causing crashes.

1 Like

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