Unexpected order result combined with Swift

Sorry for "Shouldn't this work?" question. But I can’t figure out how best to express it.

enum MyEnum { case A, B, C } let tuple = (MyEnum.C, MyEnum.A) var x: String switch tuple { case (.A, _): x = "(A, something)" case (_, .A): x = "(something, A)" case (_, .B): x = "(something, B)" case (.C, .C): x = "(C, C)" default: x = "default" } x // -> "default" 

x evaluates to "default" , which means that the default branch has been accepted.

However, I was expecting "(something, A)" and the second case register to match. From what I understood, (_, .A) should match something in the first element of the tuple, and .A in the second.

If I moved the case (_, .A) to the beginning, it will fit as I expect. Other tuples also match where I expect them.

What am I missing? Why does this not correspond to the second case?

+6
source share
1 answer

This behavior has been fixed in beta 3. Now it shows (Something, A) regardless of order.

+1
source

Source: https://habr.com/ru/post/970713/


All Articles