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
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?
source share