andremm / typedlua

An Optional Type System for Lua
563 stars 53 forks source link

Diagnostic table specs don't match language (for no apparant reason) #88

Closed Veltas closed 8 years ago

Veltas commented 8 years ago

A minor problem and possible source of confusion.

The following lets us define a table with a type taking integer indices in exchange for string or integer or nil values, with an appropriate table constructor.

local diag_test: {integer: string|integer|nil} = {"HI", 1}

And now if we give an inappropriate table constructor {"HI", 1, {"another table"}}, we get the following diagnostic:

arraydiag.tl:3:7: type error, attempt to assign '{1:string, 2:integer, 3:{1:string}}' to '{integer:(string | integer | nil)}'

Where it refers to the type we specified as {integer: (string|integer|nil)}. This obviously means the same thing, although writing the mapped type as a 1-tuple is actually a syntax error in the language:

arraydiag.tl:3:48: syntax error, unexpected '}', expecting '->'

I propose either: