Is Auto-Complete/IntelliSense broken?

do i not understand how lua works or something? i assigned 2 variables with unpack.

image
“a” correctly displays its children

image
“b” doesn’t and instead displays the same children “a” has

2 Likes

this is probably a bug. Roblox’s new intelli sense has issues sometimes with unpack.

The typechecker infers the type of an array by the type of the first entry. If you throw --!strict at the top, it’ll put up a warning on the second entry because its type is different than the first entry.

but here’s a fix that works:

local tab = {{x = 2}, {y = 2}}

local a: {x: number}, b: {y: number} = unpack(tab)

This is probably intended.

When you’re using table.unpack, it’s expected that every element inside of the array has the same type, because that’s good practice (for a heck of a lot of reasons). This is why the tuple has the same typing as the first element of the array.

Notice also in --!strict mode, it warns you that the table values are incompatible:

--!strict

local foo = {
	{a = 1},
	{b = 1}, --> there will be an incompatibility warning here
}

You can circumvent this issue by using a type for the table you’re trying to unpack:

--!strict

type foo = {
	{
		a: number?,
		b: number?,
	}
}
local foo: foo = {
	{a = 1},
	{b = 1},
}

local one, two = table.unpack(foo) --> "one" and "two" will have proper autocomplete now