Code currently in master doesn't error on this code, but as far as my understanding goes, it should:
local type IndexType = record
x: number
end
local type WrongType = record
--y: number -- uncomment this for Teal to finally throw the expected type error:
-- "wrong index type: WrongType, expected IndexType"
end
local type MapType = {IndexType: number}
local wrong_var: WrongType = {}
local index_var: IndexType = {}
local map: MapType = {[index_var] = 42}
print(map[wrong_var])
As long as WrongType is structurally a subtype of IndexType (that is, all of its fields are present in IndexType and have the same type they do in IndexType; I haven't tested for anything more complex), this code won't error.
Code currently in
master
doesn't error on this code, but as far as my understanding goes, it should:As long as
WrongType
is structurally a subtype ofIndexType
(that is, all of its fields are present inIndexType
and have the same type they do inIndexType
; I haven't tested for anything more complex), this code won't error.