Bidirectional Typing gets borked when annotating some but not all parameters in a callback

Reproduction Steps
Reproduction Steps
As of the latest update to luau (Luau Recap: September 2021), we have this new feature called bidirectional typechecking. I was wanting to make a bug report about this before the release happened, but unfortunately I had some life stuff come up.

Repro place:

InferredParamShiftsRepro.rbxl (28.9 KB)

Open up the script in ReplicatedStorage.Repro

This script has a function that takes on a callback (of type (boolean, string, number) -> ()) and does something with it later on.
Whether you pass a callback with all type-annotated or all type-inferred parameters, it will now assume infer these parameters based on the position of the type signature expected of the callback.

The problem comes when you annotate some but not all of these parameters.

In both of these cases, it will infer the types of these parameters by filling out the order of what’s expected to be passed to the onBoolStringAndNumber function. Unfortunately, it will fill out the first non-annotated parameter it encounters with the first expected parameter it finds, even if these are out of order. What you end up with is the inferred type of these parameters are shifted one position, and bad and confusing things happen.

Expected Behavior
In all callbacks passed to onBoolStringAndNumber, the parameter bool should be inferred as type boolean; str should be inferred as type string; and number should be inferred as type number

Actual Behavior
Depending on which parameters you have and have not annotated, the wrong-order type will be inferred in each non-annotated parameter.

Workaround
Annotating exactly all or exactly none of your parameter types works around this. Unfortunately, there are many use cases where I want to type just a single parameter as any or a broader type than what is passed in.

Issue Area: Studio
Issue Type: Other
Impact: Very High
Frequency: Constantly
Date First Experienced: 2021-09-29 00:09:00 (-06:00)
Date Last Experienced: 2021-09-30 00:09:00 (-06:00)

3 Likes

Thank you for the report and sorry for the trouble.
We will disable this feature today until a fix is available.

2 Likes

Small update, we have decided to keep the feature enabled.
The fix was ready, but it will only get into the release that is coming next week.

If this bug is messing with your work, we can still reconsider and disable this until next week.

2 Likes

Fix for this issue has been released, sorry for the trouble.

2 Likes

Still getting it now after restarting studio, but I’m guessing I might need to either do a fresh re-install or just wait for the next update? Thanks for the quick response though.

edit: Nevermind, it’s working for me now!

Studio version has to be 499. We now use slower rollouts for Studio updates, so you might get it later than expected.

2 Likes

This topic was automatically closed after 5 days. New replies are no longer allowed.