Reorder registration of types, to register supertypes before subtypes.#111431
Reorder registration of types, to register supertypes before subtypes.#111431Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
e86b89c to
f8ab3b3
Compare
aa48ded to
c886394
Compare
There was a problem hiding this comment.
Looks good to me! Indeed, we should register types at a minimum in order of inheritance, and maybe in order of dependency too when appropriate.
Fun fact, with GDExtension C++, you MUST register types in order of inheritance, or else the extension breaks. But it seems doing this in engine code has been unhelpfully flexible so far, so I agree we should make it more strict to ensure things are registered in order (this PR then PR #106873).
I wonder if we could allow instantiating abstract classes only for doctool, to retrieve the default values properly. The current behavior of inferring it from a subclass is pretty iffy as we see here. Otherwise yes, we'd have to sprinkle some |
|
I support reordering registrations to be in the correct inheritance order, but I wonder: is there any actual problem caused by the existing out-of-order registrations? What are we solving exactly besides making things "correct"? |
Unless the class is also C++-abstract, it should be possible.
Yes, two problems are addressed with these changes:
|
c886394 to
9843a01
Compare
|
Thanks! |
This PR addresses various inconsistencies around registration order, where subtypes are registered before their respective supertypes.
My strategy:
Texture) that are referenced in many of the blocks are registered at the top.CanvasItemwhich is moved from the 2D nodes to the Control nodes (since they're registered above 2D, and also inherit fromCanvasItem).#ifdef.I think that covers everything. I worked entirely with cut-paste; no registrations were modified, added or removed.
About the docs change
The docs instantiate classes automatically to infer default values of properties. Abstract classes cannot be instantiated. To infer default values in abstract classes, the docs will try to instantiate a subclass.
This PR triggered a re-order, which made
CanvasItem's 'designated subclass' beControlinstead ofNode2D. This causedphysics_interpolation_modeto be changed, sinceNode2Dhas a different default fromControlandCanvasItem.I fixed the problem by supplying a default directly in
CanvasItemexplicitly. This required adding an explicit path for 'non-instantiatable objects that supply their own defaults', which was previously not supported.Another solution would have been to check the superclass has the same property, and use the same default. However, this may not catch if the subtype changes the default. But, this could be added in a future PR. Even so, to respect
ADD_PROPERTY_DEFAULTwould be a prerequisite, because otherwise incorrect values may appear. So I think adding support forADD_PROPERTY_DEFAULTin abstract classes is the best way to fix this, for now.