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

classname:_init is inherited exactly one level and that is confusing #288

Open
mcclure opened this issue Feb 6, 2019 · 2 comments
Open

Comments

@mcclure
Copy link
Contributor

mcclure commented Feb 6, 2019

I am a longtime user of Penlight, I make especially heavy use of the class module.

I found something today. I check out a copy of Penlight 1.6.0. I run lua5.1 and run the following:

> class = require("pl.class")
> class.A()
> function A:_init(x) print(x) end
> A(3)
3
> class.B(A)
> B(4)
4
> class.C(B)
> C(5)
> 

B inherits from A, C inherits from B. Only A has an explicit constructor. B inherits A's constructor, but C does not inherit a constructor.
This feels like a bug, it's not in the documentation. In my testing, methods other than _init can be implicitly inherited multiple levels deep without problems.

My expected behavior is that if I don't override the constructor, it should be inherited as many levels deep as the hierarchy goes.

@mcclure
Copy link
Contributor Author

mcclure commented Feb 6, 2019

Looking at the class.lua code, the problem seems to be that call_ctor() walks all the way up the chain looking for a _init to call, but mt.__call explicitly checks only rawget(c,'_init') and rawget(base,'_init') and then gives up.

Is there some reason _init could not be "fat inherited" into the class object the same way methods are?

@alerque
Copy link
Member

alerque commented Sep 2, 2019

Is there any progress on including this? I just spent quite a while bashing my head against an issue that turns out to have it's root in my expectation of this exact things being fixed.

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

No branches or pull requests

2 participants