luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau-lang.org
MIT License
3.79k stars 349 forks source link

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

Open nothing1649 opened 4 weeks ago

nothing1649 commented 4 weeks ago

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