Both of the following code snippets produce a typechecking error only when the new type solver is enabled:
--!strict
local foo: {{number}} = {}
table.sort(foo, function(a, b)
local itemA1, itemB1 = a[1], b[1]
local itemA2, itemB2 = a[2], b[2]
return (itemA1 ~= itemB1) and (itemA1 < itemB1) or (itemA2 < itemB2)
end) -- Consider annotating the return with boolean
It is worth noting that annotating the return (which I assume are the results of the statements in brackets) as a boolean, results in another much less helpful error:
Operator '< or >=' could not be applied to operands of types unknown and unknown; there is no corresponding overload for __lt
--!strict
local foo: {number} = {}
table.sort(foo, function(a, b)
return (a ~= b) and (a < b)
end) -- Consider placing the following annotations on the arguments: a: number, b: number or instead annotating the return as boolean
In both cases, specifying the values being compared manually as the number
type helps remove the typechecking error; however this has never been needed in the past and this also doesn’t seem intentional. It seems like the arguments inputted into table.sort
are now sometimes considered the unknown
type even when they weren’t like that in the old type solver.
Expected behavior
I expect the behaviour to be similar to the old type solver where the types here are inferred to be a number and hence no typechecking errors are raised.