andremm / typedlua

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

'self' derivation in nested anonymous function declaration. #114

Closed paintdream closed 6 years ago

paintdream commented 6 years ago

Allows self in nested anonymous function. For example: local mod = { x = 0 } function mod:foo() local function inner () return self.x end return inner end works perfectly in typedlua, but if I changed inner() function into an anonymous function: local mod = { x = 0 } function mod:foo() return function () return self.x end end

It would cause an type error in typedlua (cannot index 'x' for 'nil') because the inner function cannot find correspond 'self' declaration in mod:foo().

This patch is a workaround for this problem. I'm not sure whether it would introduce any side effects or not. :)

andremm commented 6 years ago

I'm sorry for the late response, but we are migrating to a new project, so I accepted your PR at this new project. Please, check it out at https://github.com/titan-lang. Many thanks!