yaci.lua icon indicating copy to clipboard operation
yaci.lua copied to clipboard

There exists a problem when super and virtual are used at the same time.

Open jumogehn opened this issue 11 years ago • 1 comments

This problem can be found in the README.md.

It's the example under '''Instances methods'''.

1 -- Use Yaci 1.2 2 -- http://lua-users.org/wiki/YetAnotherClassImplementation 3 require("yaci") 4 5 A = newclass("A") 6 function A:test() print(self.a) end 7 A:virtual("test") -- declare test() as being virtual; see below 8 function A:init(a) self.a = a end 9 10 B = newclass("B", A) 11 function B:test() print(self.a .. "+" .. self.b) end 12 function B:init(b) self.super:init(5) self.b = b end 13 14 b = B:new(3) 15 b:test() -- prints "5+3" 16 b.super:test() -- prints "5" 17 print(b.a) -- prints "5" 18 print(b.super.a) -- prints "5"

This is the code I tested. The line number 16 causes error message like:

$ lua instances.lua 5+3 lua: instances.lua:11: attempt to concatenate field 'b' (a nil value) stack traceback: instances.lua:11: in function 'test' instances.lua:16: in main chunk [C]: ?

jumogehn avatar Feb 25 '14 07:02 jumogehn

I am getting the same error, it works when I put placeholder methods instead of setting it virtual.

omeryagmurlu avatar Jun 27 '16 18:06 omeryagmurlu