Autocomplete / types bug

Sorry for the vague title.

The bug

There seems to be a problem with the autocomplete for some types when used with a specific if condition.

How I found it

I found it while testing a function very similar to source() See attached code and noticed that autocomplete completely broke for this variable/type.

Files

Code
function source(item: item_source)
	local body = item.body
	-- autcomplete doesn't work here
	if not body:IsA("Part") and not body:IsA("Model") then
		-- same thing here
		return
	end
	-- same thing here
end

type item_source = { 
	["body"]: Part & Model
}    

--[[================================================================]]

function firstTest(item: item)
	local body = item.body
	-- autcomplete doesn't work here
	if body then
		-- but works here
			
		return
	end
	-- ... doesn't work here
end

type item = { 
	["body"]: Part 
}    

--[[================================================================]]

function secondTest(body: Part)
	local body : Part = body -- tried to force the type
	-- autcomplete doesn't work here

	if body then
		-- but works here

		return
	end
end

--[[================================================================]]

function thirdTest(body:Part)
	-- autcomplete doesn't work here

	if body:IsA("Part") then
		-- but works here

		return true
	end
end

--[[================================================================]]

-- the bug doesn't happen here
function normal(body: Part)
	
	if body then
		return
	end
end

-- At first I wasn't sure if this was a real bug or an intended behivaor
-- But after seeing the difference in 'normal()' and 'secondTest', it became clear that it was a bug

Autocomp Bug.rbxl (57.5 KB)

Thank you for the report, and the reproduction! Agreed, definitely a bug. We’ll try to tackle this and keep you in the loop as a fix goes out.

1 Like

Hello, a fix for this will make it in next week. However, it only applies to the New Luau Type Solver. If you are not already using it, you can switch by clicking Workspace > Property Editor > Scripting Section > UseNewLuauTypeSolver → set this to enabled.

Thank you!