-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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 invalid return from some more _get/_set
#84060
Conversation
be96218
to
6bd6e14
Compare
@@ -48,12 +48,14 @@ bool Bone2D::_set(const StringName &p_path, const Variant &p_value) { | |||
} else if (path.begins_with("default_length")) { | |||
set_length(p_value); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is enforced by format, unless I move the closing brackets into the #ifdef
Given that all classes with the wrong code are related, the person who implemented these methods probably didn't know how to use them correctly. There is no reason to write it like that.
|
Not unless you also add See for example |
Yep, the blocks should return.
That one is wrong too. |
I mean this syntax is used in plenty of places, can modify it here to simplify it but kept the changes minimal |
Compare: bool SkeletonModification2DLookAt::_get(const StringName &p_path, Variant &r_ret) const {
String path = p_path;
if (path.begins_with("enable_constraint")) {
r_ret = get_enable_constraint();
} else if (path.begins_with("constraint_angle_min")) {
r_ret = Math::rad_to_deg(get_constraint_angle_min());
} else if (path.begins_with("constraint_angle_max")) {
r_ret = Math::rad_to_deg(get_constraint_angle_max());
} else if (path.begins_with("constraint_angle_invert")) {
r_ret = get_constraint_angle_invert();
} else if (path.begins_with("constraint_in_localspace")) {
r_ret = get_constraint_in_localspace();
} else if (path.begins_with("additional_rotation")) {
r_ret = Math::rad_to_deg(get_additional_rotation());
}
#ifdef TOOLS_ENABLED
else if (path.begins_with("editor/draw_gizmo")) {
r_ret = get_editor_draw_gizmo();
}
#endif // TOOLS_ENABLED
else {
return false;
}
return true;
} To: bool SkeletonModification2DLookAt::_get(const StringName &p_path, Variant &r_ret) const {
String path = p_path;
if (path.begins_with("enable_constraint")) {
r_ret = get_enable_constraint();
return true;
} else if (path.begins_with("constraint_angle_min")) {
r_ret = Math::rad_to_deg(get_constraint_angle_min());
return true;
} else if (path.begins_with("constraint_angle_max")) {
r_ret = Math::rad_to_deg(get_constraint_angle_max());
return true;
} else if (path.begins_with("constraint_angle_invert")) {
r_ret = get_constraint_angle_invert();
return true;
} else if (path.begins_with("constraint_in_localspace")) {
r_ret = get_constraint_in_localspace();
return true;
} else if (path.begins_with("additional_rotation")) {
r_ret = Math::rad_to_deg(get_additional_rotation());
return true;
}
#ifdef TOOLS_ENABLED
if (path.begins_with("editor/draw_gizmo")) {
r_ret = get_editor_draw_gizmo();
return true;
}
#endif // TOOLS_ENABLED
return false;
} Can go with the second syntax if desired, but I think it's for a separate PR cleaning up and unifying the style |
I think the existing syntax has the right to be if there are further actions required after the if-else block. If not, returning early should be clearer, since it indicates that this is the last step and you don't need to read any further. But I also agree it can be pretty noisy. So no strong opinion either way. |
Ok I misunderstood the code. This syntax is indeed better. |
6bd6e14
to
f7f987a
Compare
Invalidly returned `true` on the non-matched path
f7f987a
to
3ef6314
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention is that we have many set and gets, there's a complicated switch / if else statement that else returns the the least likely and then falls through to the most likely Boolean value.
Thanks! |
Thank you! |
Cherry-picked for 4.1.4. |
Invalidly returned
true
on the non-matched pathFollow-up to:
_get/_set
#84054Reviewers: If these cases are invalid (i.e. all paths should return true) then please explain why and I'll add a note for it instead