luau
luau copied to clipboard
TypeError when indexing table with union/intersection type of identical types
As of release 0.628, attempting to index a table which has the type of a union/intersection only consisting of the same type throws a TypeError. This can be reproduced with the following code:
--!strict
type array = {number}
type union = array | array
type intersection = array & array
local tableUnion: union = {1, 2, 3}
print(tableUnion[1]) --TypeError: Expected type table, got 'array | array' instead
local tableIntersection: intersection = {1, 2, 3}
print(tableIntersection[2]) --TypeError: Expected type table, got 'array & array' instead
@alexmccord Is the new solver out in studio? I get a similar warning ...:
type Alex = Model | Model
local var: Alex = {} :: any
print(var.Name) -- no warning
var.Name = "value" -- Expected table got Model|Model
Closing this as new solver with a fix for this issue is now available to use.
This one might be fixed in the old solver, but I haven't tested it. If there's still an error, we do not plan to update the old solver.