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.

Zhao Xin
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to