Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep Copy function with support for metatables fail to infer the type. #1398

Open
TenebrisNoctua opened this issue Sep 12, 2024 · 0 comments
Labels
bug Something isn't working new solver This issue is specific to the new solver.

Comments

@TenebrisNoctua
Copy link

This is a deep copy function that I made for tables with generics that also support metatables, and in the new type solver it fails to infer the type of tmetatable variable. (Produces a warning with a blocked-1234 statement.)

local function deepCopy<T>(original: {T}): {T}
	local copy = table.clone(original)

	for key, value in original do
		if type(value) == "table" then
			local tmetatable = getmetatable(value); -- union<*blocked-123456*, (buffer | class | function | number | string | table | thread | true) & *blocked-123456*> Function only returns 0 values, but 1 is required here
			copy[key] = if not tmetatable then deepCopy(value) else setmetatable(deepCopy(value), tmetatable)
		end
	end

	return copy
end
@TenebrisNoctua TenebrisNoctua added the bug Something isn't working label Sep 12, 2024
@aatxe aatxe added the new solver This issue is specific to the new solver. label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new solver This issue is specific to the new solver.
Development

No branches or pull requests

2 participants