The new type solver beta incorrectly handles recursive functions paired with local variables.
In the attached code example, you can see that function f
calls itself recursively, taking advantage of uninitialized variable syntax.
The nested function call to f
sees the type as nil-able although it is impossible for the value to be nil here.
The old type solver handles this correctly
--!strict
--Example recursive function that counts up to 3
local f; f = function(x:number):number
x += 1
if x < 3 then
return f(x)--Type Error: Value of type '((number) -> number)?' could be nil
end
return x
end
print(f(1))-- > 3
Expected behavior
The nested call to function f
should recognize the final type of the variable without the need of type-casting
Betas enabled:
- New Type solver beta
- Incremental typechecking