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)