[swift-evolution] [swift-evolution-announce] [Review] SE-0043 Declare variables in 'case' labels with multiple patterns
jordan_rose at apple.com
Wed Mar 16 21:36:59 CDT 2016
> On Mar 16, 2016, at 18:10 , Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> • What is your evaluation of the proposal?
> Good stuff.
> How exact does the type match have to be? Can they be two subclasses of a different superclass? Can they conform to common protocols? Can they conform to no common protocols and just be `AnyObject` or `Any`?
> Is there a way to specify the type, either to get an exact match or just to ask or a supertype? If you do that, does it have to be specified on both, or only one? Something like:
> case let .Case1(x: SignedIntegerType, 2), let .Case2(2, x):
In GregT's current implementation, the types have to be an exact match. You can use the existing "as Foo" constraint to specify a type, but it must be specified everywhere that that wouldn't be the inferred type. (See my earlier message to Andrii C: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160314/012779.html) Note that that also isn't "as!"; if used with a subtype instead of a supertype, it imposes (and has always imposed) an additional constraint on the match.
More information about the swift-evolution