teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.02k stars 101 forks source link

Nillable record fields #735

Closed Frityet closed 5 months ago

Frityet commented 5 months ago

Right now record fields cannot be marked as nillable, and with the <total> attribute they must be defined. Is it possible to have an annotation for this? even if it doesn't do anything, it would be very very useful for annotating structs for recreating the same type in another language. I discovered I would need this feature due to the fact I am trying to use Teals lexer and parser from C++, and porting the types across has caused me to make every field optional, which is not optimal.

Frityet commented 5 months ago

maybe something like, to keep it inline with the params

local record MyRecord
    i: integer
    s?: string
end

local x: MyRecord = {} --variables are `<total>` by default, warning that `i` isn't inited