You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
macOS Sierra Version 10.12.2 (16C67)
Xcode Version 8.2 (8C38)
Additional Detail from JIRA
Votes
2
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: a4f994ae56f17272258c1e9ae6d2181a
relates to:
SR-1121 Custom pattern matching with enum types in Swift 2.2 not working as expected
Issue Description:
Going from this working code in the Swift Language Guide:
func ~=(pattern: String, value: Int) -> Bool {
returnpattern == "\(value)"
}
letpoint = (0, 0)
switchpoint {
case ("0", "0"):
print("(0, 0) is at the origin.")
default:
print("The point is at (\(point.0), \(point.1)).")
}
I expect to be able to write the following pattern matcher:
enumPattern {
casezero
}
func ~=(pattern: Pattern, value: Int) -> Bool {
returnvalue == 0 && pattern == .zero
}
switchpoint {
case (Pattern.zero, Pattern.zero):
print("(0, 0) is at the origin.")
default:
print("The point is at (\(point.0), \(point.1)).")
}
However, I observe that the code does not compile, with the following errors:
Environment
macOS Sierra Version 10.12.2 (16C67)
Xcode Version 8.2 (8C38)
Additional Detail from JIRA
md5: a4f994ae56f17272258c1e9ae6d2181a
relates to:
Issue Description:
Going from this working code in the Swift Language Guide:
I expect to be able to write the following pattern matcher:
However, I observe that the code does not compile, with the following errors:
I can however work around the issue by using another data type. The following
struct
based code compiles and runs as expected:The text was updated successfully, but these errors were encountered: