luau
luau copied to clipboard
[New Solver] fails to track type state of explicitly assigned properties
Consider this code example:
type Item = {
specialAttributes: { string }?
}
local myItem: Item = {}
myItem.specialAttributes = {}
table.freeze(myItem.specialAttributes) -- errors!
This produces a type error today:
TypeError: Type '{string}?' could not be converted into '{- -}'
this error is clearly wrong -- we have explicitly defined myItem.specialAttributes, and so it's not possible for it to be {string}? -- it would now be {string}.
Note that in my case, myItem was sourced after iterating over a table, and so the specialAttributes assignment (and freeze) occurs inside the loop. There are obvious workarounds (like using table.freeze to wrap the assignment), but the core issue remains.
Note: this might be a dupe of #1970, but I'm not sure that it's exactly the same.