luau icon indicating copy to clipboard operation
luau copied to clipboard

New type solver having is having issues with Vectors

Open WatermelonArray opened this issue 1 year ago • 1 comments

Hi, I think the issue is caused by when the solver tries to create a new Vector3 or Vector2 via the constructor and doesn't like it. Strings and numbers do not seem to cause this issue.

Here is the code:

--!strict

local class = {}
local targetVelocity: Vector3 = Vector3.new()

function class:SetDirectionVelocity(axis: Vector2)
	targetVelocity = Vector3.new(axis.X, targetVelocity.Y, axis.Y) -- Vector3 and Vector2 throws this error.
end

return class

Error: TypeError: Type function instance union<Vector3, *blocked-49207*> is uninhabited [Type Error](https://luau.org/typecheck): Type 'nil' could not be converted into 'Vector3'

This is what the error shows in VSCode using the JohnnyMorganz's Luau lsp: image

This is what it shows within Studio: image

WatermelonArray avatar Dec 09 '24 23:12 WatermelonArray

Did some testing and noticed this also occurs with table self-initialization. Example code:

local p = {}
function p.new(x: number?)
    return {
        x = x or 0
    }
end

local test_table = p.new()
function update_test_table()
    test_table = p.new(test_table.x)
end

Type Error: Type 'nil' could not be converted into 'union<{ x: number }, union<{ x: number }, *blocked-3197*>, *blocked-3197*>'; type nil (nil) is not a subtype of union<{ x: number }, union<{ x: number }, *blocked-3197*>, *blocked-3197*>~~> (never)

foshesss avatar Dec 18 '24 11:12 foshesss

Hello! Thank you for the report, and for beta testing the new type solver. It looks like this issue has been resolved, in fact your example has been added to our test suite! Please feel free to re-open this issue if this specific error is still occurring.

hgoldstein avatar Jun 04 '25 23:06 hgoldstein