The following Swift code compiles:
enum GraphDataSource {
case array(data: [Double], start: Double?, step: Double?)
case pairs(XYValues: [Double: Double])
case pairs(dateValues: [Date: Double])
case function((Double) -> Double?)
func localizedName() -> String {
// TODO: Create localizable strings
return NSLocalizedString(Mirror(reflecting: self).children.first?.label ?? "", comment: "")
}
}
It has two enum cases named pairs.
But when I try to extract associated value, it turns out that I can't choose the one I want.
var graphData = GraphDataSource.function(sin)
switch graphData {
case .pairs(dateValues: let vals):
vals.keys.forEach({print($0)})
case .pairs(XYValues: let xy): // without this case everyting compiles OK
xy.keys.forEach({print($0)})
default:
break
}
The error is: "Tuple pattern element label 'XYValues' must be 'dateValues'". Is this normal? Feels like compiler should either disallow cases of the same name or allow to switch on both.