luau
luau copied to clipboard
Bad error message when passing read property to non-read function
In the new solver, the following code:
--!strict
type Item = {
age: number
}
type ReadonlyItem = {
read age: number
}
local function birthday(arg: Item): () end
local doge: ReadonlyItem = {age = 41}
birthday(doge)
will produce the following error message today:
TypeError: Type 'number' could not be converted into 'number'
(or more generically, "Type 'T' could not converted into 'T').
This is because we pass a type (ReadonlyItem) with a 'readonly' key to a function that does not mark this as 'readonly' (Item). If we just used Item everywhere, rather than ReadonlyItem, there would be no errors.
This error message is obviously non-nonsensical (though the error as far as I can tell is correct). It would be a better experience if the message was more descriptive.
The error message has improved quite a bit since I posted this issue, though it is still arguably not perfect. The latest error message reads as:
TypeError: Type 'ReadonlyItem' could not be converted into 'Item'; this is because accessing
ageresults innumberin the former type andnumberin the latter type, andnumberis not a subtype ofnumber