Luau Type Checker Incorrectly Handling Types Within IF Statements

There are two conditions I have noticed where my Luau types are incorrect. The first one is in this example:


The CustomKeyframe type is incorrectly coerced to a boolean, even though the actual part of the check I used was the Broken property of the object… not the object itself

Another case where the type checker failed was in this example scenario:


Here the method’s types function just fine, but when placed in an if statement:

It appears to lose track of the type and casts the method call to unknown

Expected behavior

The if statement should be checking the type of the object and coercing / casting it appropriately given the nature of the clause, as opposed to not understanding method call types nor properties of custom objects. It also should not abstract away custom types, like expanding CustomKeyframe into its full type information, it should just say the CustomKeyframe type for self

Additional examples found:


I believe this one, however, is not a related bug and is just due to the type checker not consolidating types by operands (i.e. expecting / type checking T if and only if T supports __le like in C++, as opposed to expecting T to take on all types, i.e. allowing T=Vector3 but not T=Instance resulting in find<Instance>({...}, ...) being an erroneous function call that results in a type error)