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

GDScript: Add error when exporting node in non Node-derived classes #82843

Merged

Conversation

dalexeev
Copy link
Member

@dalexeev dalexeev commented Oct 5, 2023

@dalexeev dalexeev added this to the 4.2 milestone Oct 5, 2023
@dalexeev dalexeev requested a review from a team as a code owner October 5, 2023 11:00
@dalexeev dalexeev changed the title GDScript: Add error when exporting node in non [Node]-derived classes GDScript: Add error when exporting node in non Node-derived classes Oct 5, 2023
Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice!

@akien-mga akien-mga merged commit cd7c50f into godotengine:master Oct 5, 2023
15 checks passed
@dalexeev dalexeev deleted the gds-export-node-only-in-nodes branch October 5, 2023 14:56
@akien-mga
Copy link
Member

Thanks!

@@ -5544,7 +5544,7 @@ Error GDScriptAnalyzer::analyze() {
// Apply annotations.
for (GDScriptParser::AnnotationNode *&E : parser->head->annotations) {
resolve_annotation(E);
E->apply(parser, parser->head);
E->apply(parser, parser->head, nullptr);
Copy link
Member

@aaronfranke aaronfranke Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser->head is a ClassNode *, so this line should be:

E->apply(parser, parser->head, parser->head);

I have added a fix for this to #67777.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, p_class is the class that p_target is in. The root class is not in any other class. This is a subtle detail, but for example if an annotation is applied to an inner class (we don't have such a case right now), then p_target will be the class, and p_class will be its outer class. Therefore, if you do not need the context class, then it is important to use p_target rather than p_class, even this requires static_cast.

Copy link
Member

@aaronfranke aaronfranke Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed that detail before. I've updated my PR and add a comment in the abstract annotation apply method for why we are using p_target instead of p_class.

Maybe p_class should be renamed to p_in_class? Since it's the class the target is in.

@YuriSizov
Copy link
Contributor

Just a small note: if we are referring to some unspecified limitations, we should link to some place that explains what those are. Do we have an article that goes into such detail about Node exports?

@dalexeev
Copy link
Member Author

dalexeev commented Oct 6, 2023

Just a small note: if we are referring to some unspecified limitations, we should link to some place that explains what those are. Do we have an article that goes into such detail about Node exports?

Fair point. I remember that there are issues with exporting nodes in @tool mode, but I'm not sure about other issues, which of them are limitations and which are bugs. So I left room for interpretation. I wanted to warn that exporting nodes is less stable than exporting node paths and may not work in non-standard scenarios.

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

Successfully merging this pull request may close these issues.

When using a Node exported through a Resource, you can not listen to its signals.
5 participants