luau icon indicating copy to clipboard operation
luau copied to clipboard

TypeError when indexing table with union/intersection type of identical types

Open nothing1649 opened this issue 1 year ago • 1 comments

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

nothing1649 avatar Jun 06 '24 07:06 nothing1649

@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

0x13479 avatar Sep 28 '24 12:09 0x13479

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.

vegorov-rbx avatar Feb 14 '25 15:02 vegorov-rbx