teal-language / tl

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

Return statement does not get type checked #639

Closed nikitug closed 1 year ago

nikitug commented 1 year ago

I've noticed that the code below does not produce unknown field y error, but I'd expect it to do so.

local type X = record
  x: number
end

local function test(): X
  return { y = 1 }
end

test()

P.S. Thank you for the great Lua tools! :)

hishamhm commented 1 year ago

@nikitug Are you sure you are running the latest version? It does produce the error in 0.15.1, and also testing online with the master branch:

https://teal-playground.netlify.app/?c=bG9jYWwgdHlwZSBYID0gcmVjb3JkCiAgeDogbnVtYmVyCmVuZAoKbG9jYWwgZnVuY3Rpb24gdGVzdCgpOiBYCiAgcmV0dXJuIHsgeSA9IDEgfQplbmQKCnRlc3QoKQ%3D%3D

(Looks like there's a quirk in the playground — you need to edit something (e.g. prest Enter) so that the compiler refreshes, and then the "y" will appear underlined in red and when you hover it, it does say unknown field y)

hishamhm commented 1 year ago

Closing this issue for now (I've opened one in the playground for the refresh issue) — feel free to reopen if you find a different test case where this problem persists!

nikitug commented 1 year ago

@hishamhm Thank you for your quick reply! You are right – I have not noticed I've been using a global executable from homebrew (not sure how I even have it though), not the one from my home dir with the latest version.