[swift-evolution] 'T != Type' in where clause

Anton Zhilin antonyzhilin at gmail.com
Tue Feb 28 02:30:56 CST 2017


But it already works without where T != Self. Moreover, I guess, this
solution is currently considered “good enough” not to introduce additional
complexity to type system.
Also, on and and or—the former already exists in the form of &, and the
latter is listed in commonly proposed rejected features.

2017-02-28 7:23 GMT+03:00 Robert Bennett via swift-evolution <
swift-evolution at swift.org>:

protocol P1 {}

protocol P2 {
        // Now, there's no ambiguity
        static func +<T: P1 where T != Self>(lhs: Self, rhs: T) -> Self
        static func +<T: P1 where T != Self>(lhs: T, rhs: Self) -> Self
        static func +(lhs: Self, rhs: Self) -> Self
}

struct S: P1, P2 {
        static func +<T: P1 where T != Self>(lhs: T, rhs: S) -> S {
                return rhs
        }
        static func +<T: P1 where T != Self>(lhs: S, rhs: T) -> S {
                return lhs
        }
        static func +(lhs: S, rhs: S) -> S {
                return lhs
        }
}

Some thought would have to be given to how to handle subtype relationships
— probably you would use the polymorphic type of the object at the call
site.

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170228/f9bca6f4/attachment.html>


More information about the swift-evolution mailing list