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

Allow standalone ternary expressions #71120

Merged
merged 1 commit into from Jan 25, 2023
Merged

Conversation

jordigcs
Copy link
Contributor

@jordigcs jordigcs commented Jan 9, 2023

Closes #71065

Removes STANDALONE_EXPRESSION warning and allows void expressions for ternary operator

@jordigcs jordigcs requested a review from a team as a code owner January 9, 2023 17:05
@jordigcs jordigcs changed the title Fix ternary op expression being analyzed as a return Fix standalone ternary erroring when using void methods Jan 9, 2023
@akien-mga akien-mga added this to the 4.0 milestone Jan 9, 2023
@akien-mga akien-mga requested a review from vnen January 9, 2023 17:17
@vnen
Copy link
Member

vnen commented Jan 9, 2023

This also incorrectly applied to standalone ternaries.

Well, "incorrectly" is debatable as I wrote in the issue. The ternary expression is expected to return something and it cannot do so with void methods, so it does make sense that it fails.

As I also wrote in the issue, we need to decide if using it as a shorthand one-line if statement is acceptable.

@jordigcs
Copy link
Contributor Author

jordigcs commented Jan 9, 2023

Ah, I thought that was already accepted behavior for the ternary op. I'll mark this as draft for now. Thanks!

@jordigcs jordigcs marked this pull request as draft January 9, 2023 18:44
@vnen
Copy link
Member

vnen commented Jan 19, 2023

@jordigcs It seems the consensus is that this feature is wanted and this is a proper solution. The only thing missing is what I mentioned in my comment: the ternary operator should not give the STANDALONE_EXPRESSION warning. Do you want to add it to this PR?

@jordigcs
Copy link
Contributor Author

Sure, I'll get that done in a moment.

@jordigcs
Copy link
Contributor Author

Done!

@jordigcs jordigcs marked this pull request as ready for review January 19, 2023 20:28
@jordigcs jordigcs changed the title Fix standalone ternary erroring when using void methods Allow standalone ternary expressions Jan 20, 2023
@vnen vnen merged commit e93266b into godotengine:master Jan 25, 2023
@vnen
Copy link
Member

vnen commented Jan 25, 2023

Thanks!

@jordigcs jordigcs deleted the ternary branch January 25, 2023 15:37
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.

GDScript 2.0: Error when trying to call a method with a ternary operator
3 participants