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

Fix variables from being renamed with a property #7186

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Conversation

D8H
Copy link
Collaborator

@D8H D8H commented Nov 24, 2024

No description provided.

@D8H D8H requested a review from 4ian as a code owner November 24, 2024 21:49
@@ -69,16 +71,21 @@ class GD_CORE_API ExpressionPropertyReplacer
void OnVisitNumberNode(NumberNode& node) override {}
void OnVisitTextNode(TextNode& node) override {}
void OnVisitVariableNode(VariableNode& node) override {
if (isParentTypeAVariable) {
// Do nothing, it's a variable.
if (node.child) node.child->Visit(*this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it useful to explore the node's children if this one is __ (I'm not sure what it means)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, because of expression like: MyVariable.MyChild[MyProperty].

Copy link
Owner

Choose a reason for hiding this comment

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

In other words, we must continue to explore because properties could be used in children (becuase a variable node can have sub variables, or bracket accessors, which allows to enter a sub-expression inside the brackets ([MyProperty]. [1 + MyProperty]...), and this sub-expression must be explored to rename the property that could be there.

auto& propertiesContainersList =
projectScopedContainers.GetPropertiesContainersList();

// Match the potential *new* name of the property, because refactorings are
// done after changes in the variables container.
projectScopedContainers.MatchIdentifierWithName<void>(
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why this "MatchIdentifierWithName" is not doing its job? If it's a variable, it should match it (and so do nothing), no?

Copy link
Collaborator Author

@D8H D8H Nov 26, 2024

Choose a reason for hiding this comment

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

I think isParentTypeAVariable is still required because when a node is an identifier, we don't want to replace it if the expression is a variable parameter even if the variable doesn't exist.
MatchIdentifierWithName doesn't know about the expected type for the current node. This is why isParentTypeAVariable is needed.

"MyExtension::GetVariableAsNumber(MyVariable.MyChild[MyRenamedProperty])");
}

SECTION("(Events based behavior) property not renamed (in variable parameter)") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the test for it.

@D8H D8H merged commit e111706 into master Nov 26, 2024
5 of 6 checks passed
@D8H D8H deleted the fix-property-rename branch November 26, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants