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

Display correct symbol in warning when unique name is used without @onready annotation #102389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Meorge
Copy link
Contributor

@Meorge Meorge commented Feb 4, 2025

Closes #102386.

This adds a few lines of code to the procedure generating the warning. It simply checks if the path being used in shorthand begins with "%", and if so uses that symbol instead of "$" for the warning.

Godot.4.4.Fixed.Error.Message.about.Unique.Name.Nodes.mp4

@Meorge Meorge requested a review from a team as a code owner February 4, 2025 01:37
@dalexeev dalexeev added this to the 4.4 milestone Feb 4, 2025
GDScriptParser::GetNodeNode *get_node_node = static_cast<GDScriptParser::GetNodeNode *>(expr);
String offending_syntax = "get_node()";
if (is_using_shorthand) {
if (get_node_node->full_path.begins_with("%")) {
Copy link
Member

Choose a reason for hiding this comment

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

There is use_dollar property:

bool use_dollar = true;

Compare: %Node and $"%Node". Also please add a test.

@@ -1093,7 +1093,16 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
}
}
if (is_get_node) {
parser->push_warning(member.variable, GDScriptWarning::GET_NODE_DEFAULT_WITHOUT_ONREADY, is_using_shorthand ? "$" : "get_node()");
GDScriptParser::GetNodeNode *get_node_node = static_cast<GDScriptParser::GetNodeNode *>(expr);
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this into the if (is_using_shorthand) condition. Otherwise it's an incorrect cast if the type is not GET_NODE.

parser->push_warning(member.variable, GDScriptWarning::GET_NODE_DEFAULT_WITHOUT_ONREADY, is_using_shorthand ? "$" : "get_node()");
GDScriptParser::GetNodeNode *get_node_node = static_cast<GDScriptParser::GetNodeNode *>(expr);
String offending_syntax = "get_node()";
if (is_using_shorthand) {
Copy link
Member

Choose a reason for hiding this comment

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

There are 2 variables: is_get_node and is_using_shorthand. Are you sure that this is the correct one?

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.

"The default value is using "$" which won't return nodes..." warning despite using Unique Name ("%")
2 participants