Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jumogehn opened this issue Feb 25, 2014 · 1 comment

Comments

@jumogehn
Copy link

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]: ?

@omeryagmurlu
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants