You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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?
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.
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: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.
The text was updated successfully, but these errors were encountered: