Vector.lerp type expects number return

This isn’t a dot product fellas.

6 Likes

Type still expects number to return. vector is not a number.
I have to absolve the issue by slapping a good old :: any on the returned value

1 Like

Oh yeah the language itself is the issue; just pulled up vscodium and that’s also reporting the return type as number. Will go ahead and report that now if not done so already. Will provide link here when done

1 Like

Yes, all built-in type definitions are part of Luau itself, so the Issue would be valid:

Thanks for the link.

I’ve created the issue here:

If there’s any conventions that I’ve failed to adhere to since this is my first issue creation, let me know.

How does something like this get pushed? Just wondering

I mean, it’s a simple typo to make. It doesn’t fail any types of existing unit tests in Luau, those can only check the runtime behaviour. Maybe you could make the argument that there should be a test that verifies every function returns the same value types as the type definitions say they do, but otherwise they are pretty disconnected from each other.

1 Like

I guess yeah, but this also denotes that there were no tests for vector.lerp to return a vector right? And whatever tests were made were written with a number return? Assuming that returning a vector is the original intent of vector.lerp (aside from its return type being set to number). I don’t know how tests work

There are tests which ensure vector.lerp behaves as expected:

It’s just that the Type System and the Runtime are not connected at all. The Type System could tell Studio that vector.lerp returns a SlidingBallConstraint, and Studio could give you a warning if your code assumes it returns a vector, but that has no influence on how your code actually runs. You won’t get any errors, and type definitions are not observable by code, only the types of values. typeof(vector.lerp(a, b, t)) will still be "vector" regardless of what the Type System says

1 Like

Ok, I understand now thanks! As for

Maybe you could make the argument that there should be a test that verifies every function returns the same value types as the type definitions say they do, but otherwise they are pretty disconnected from each other.

How could this get suggested? I think this would be nice

It would probably go through the Luau GitHub repository because it’s not really relevant to Roblox, but I’m not sure this would really be implemented because the impact is generally pretty small and this is not really a common occurrence, and it seems like it would be a little difficult to implement. Maybe a better suggestion would be to run the Type Checker over all the behavior tests (such as the one I linked) as a test itself, which should be a lot simpler to implement for basically the same effect.

1 Like

The dev is here.

The fix is on the way and will be available according our release cycle soon.

It is the first thing I tried to add after noticing this bug. Unfortunately it doesn’t work because conformance tests contain a lot of incorrectly typed(but still valid!) code. For example from tests:

-- function calls
local function foo(a, b) return b end
assert(foo(1) == nil)
assert(foo(1, 2) == 2)
assert(foo(1, 2, 3) == 2)

It is a type error from the point of view of type checker even with nonstrict flag to call foo with not enough arguments.

2 Likes

Hey, can you do some extra tests for native codegen? vector.lerp appears to be.. incredibly wrong in some cases, caused my NPCs to teleport around like this:

I traced it down to my GetPosition function, which I recently swapped to vector.lerp under native codegen. So, I debugged the values very sloppily like this:

…and, it seemed to never interpolate X. It always ends up being 0, despite 10 - (13 * 0.431) definitely not being 0.

Turning off native codegen completely fixed this:

I’m happy to make a new bug report for this, but I would rather not create another post for vector.lerp - something’s just up with it in general lol (probably something to do with an FMA optimization if I had to guess), really weird rollout

2 Likes

Thank you for reporting it.
It is incredible how that bug in x64 instruction encoding slipped through tests we have. it was executed but by accident it well behaved on test cases.
I’ve disabled native codegen for vector.lerp until the bugfix reaches the prod.

1 Like

Thank you very much for getting to it so quick!