teal-language / tl

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

Declare record functions on a nested record #652

Closed hishamhm closed 1 year ago

hishamhm commented 1 year ago

Discussed in https://github.com/teal-language/tl/discussions/648

Originally posted by **Andre-LA** April 10, 2023 In the tutorial, there's this paragraph and example: > You can also declare record functions after the record definition using the regular Lua colon or dot syntax, as long as you do it in the same scope block where the record type is defined ```lua function Point:move(dx: number, dy: number) self.x = self.x + dx self.y = self.y + dy end ``` This works, however, I'm curious if it's possible to do the same thing on a nested record like this? ```lua local record Math record Point x: number y: number end end function Math.Point:move(dx: number, dy: number) self.x = self.x + dx self.y = self.y + dy end ``` The code above gives the error "cannot add undeclared function 'move' outside of the scope where 'Math.Point' was originally declared", but I don't didn't understood how to declare it on the correct scope.
hishamhm commented 1 year ago

Fixed in 0bdec774a91854cf661c05b1b806bd594437eb8c!

@Andre-LA thanks for reporting!