Vector3 type and Luau vector type are incompatible with eachother despite being the same thing

As of version 0.656, the Vector3 type is incompatible with the newly added vector type (returned from the Luau vector library) despite them being completely identical. Since typeof(vector) == 'Vector3' and they act the same at runtime it should be expected that the types are compatible.

--!strict
local _:Vector3 = vector.zero --Type 'vector' could not be converted to 'Vector3'
local _:vector = Vector3.zero --Type 'Vector3' could not be converted to 'vector'

image

Expected behavior

Either vector becomes an alias of Vector3 (or vice versa), or the types become compatible with eachother. However since .x, .y and .z are used to access the vector type and .X, .Y and .Z are used on Vector3 there should be typechecking support for accessing components regardless of the case used.

8 Likes

Thanks for the report! I filed a ticket in our internal database.

1 Like

This still happens today. This bug makes it very hard for me to want to switch from Vector3 to vector for any Roblox code.

1 Like

You shouldn’t be trying to switch unless you plan on making your code compatible with stock Luau. Vector3 and most of its library functions are already interned with the native vector type and also have codegen IR hooks attached to their metamethods that compile to very efficient SIMD assembly.

You may be able to squeeze some performance out if you use the vector library, but the wins have become more deterministic recently (Vector3.Magnitude can sometimes beat vector.magnitude if you’re reading from it often, thanks to memoization).


For what it’s worth, this is entirely doable in the current type system. The vector type is currently represented with an extern type that can be ‘inherited’ from, so all that needs to be done is change the type definition for Vector3 to extend from vector and boom you can use a Vector3 wherever a vector is expected.

The problem is the interop is one way (can’t assign a vector to BasePart.Position, etc.) but this makes sense from a correctness standpoint because they technically aren’t the same.

6 Likes

Extremely informative – thank you so much!

1 Like