[swift-users] matching a protocol value in multiple patterns is not yet supported; use separate cases instead
Jordan Rose
jordan_rose at apple.com
Wed Jul 19 11:28:18 CDT 2017
> On Jul 18, 2017, at 18:17, Zhao Xin via swift-users <swift-users at swift.org> wrote:
>
> I encounter this error today. "matching a protocol value in multiple patterns is not yet supported; use separate cases instead"
>
> Sample code:
>
> import Foundation
>
> protocol NameProtocol {
> var name:String { get }
> }
>
> struct Cat:NameProtocol {
> let name:String
> }
>
> struct Dog:NameProtocol {
> let name: String
> }
>
> enum AnimalType {
> case catType(cat:NameProtocol)
> case dogType(dog:NameProtocol)
> }
>
> struct Animal {
> let type:AnimalType
>
> func printName() {
> switch type {
> case .catType(let animal), // matching a protocol value in multiple patterns is not yet supported; use separate cases instead
> .dogType(let animal):
> print(animal.name)
> }
> }
> }
>
> let cat = Cat(name: "kitty")
> let catType = AnimalType.catType(cat: cat)
> let animal = Animal(type: catType)
> animal.printName()
>
>
> I am wondering which proposal this is? And will it be implemented in Swift 4.0? I search the error as keywords, but didn't get the expected results.
It’s mostly just a bug. In Swift 3.1 this code was accepted but did the wrong thing at run-time. So we put in the error message until we can get around to fixing that, which at this point is unlikely to happen for Swift 4. There’s no new proposal needed, just more time to work on it.
Sorry for the inconvenience,
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170719/3c3668eb/attachment.html>
More information about the swift-users
mailing list