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 logic errors in match-statement Array & Dictionary patterns #57151

Merged

Conversation

cdemirer
Copy link
Contributor

Fixes #57004
Fixes #57150

This fixes 2 logic errors about match statements.

The first is about the order of logical operations. Currently, ORing with the result of the previous pattern of the same branch happens before checking the elements of the Array / Dictionary (for the respective patterns). This causes weird behavior, ranging from skipped cases (#57004) to runtime errors:

func _ready():
    match 1:
        1, [2]: # Runtime error: Invalid get index '0' (on base: 'int').
            print('A')

The second is specific to the Dictionary Pattern. When the pattern has a key with no value supplied, it is supposed to require the existence of the key in order to successfully match. However, currently its existence only contributes to the result if there is also a value supplied. (#57150)

@cdemirer cdemirer requested a review from a team as a code owner January 24, 2022 20:05
@akien-mga akien-mga added this to the 4.0 milestone Jan 24, 2022
@vnen
Copy link
Member

vnen commented Feb 23, 2022

Looks good. Could you add some test cases for this?

@cdemirer cdemirer force-pushed the fix-match-array-dict-pattern-logic-error branch from 7a29b9d to 4735f89 Compare March 2, 2022 11:02
@cdemirer cdemirer force-pushed the fix-match-array-dict-pattern-logic-error branch from 4735f89 to 3afe50c Compare March 2, 2022 11:05
@cdemirer
Copy link
Contributor Author

cdemirer commented Mar 2, 2022

Added test cases.

@vnen vnen merged commit 15740c3 into godotengine:master Jun 15, 2022
@vnen
Copy link
Member

vnen commented Jun 15, 2022

Thanks! And sorry for the delay.

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