[swift-dev] New warning message while switching on an enum
Robert Widmann
devteam.codafi at gmail.com
Tue May 9 13:12:25 CDT 2017
It’s mine, yep. It looks like it’s classifying the cast in the first pattern as a variable binding instead of an expression pattern. I’ll push a fix later.
Thanks!
> On May 9, 2017, at 1:52 PM, Jordan Rose <jordan_rose at apple.com> wrote:
>
> That looks like a bug to me, since of course the first pattern won't always match. I suspect this is Robert's work on trying to make the exhaustive checks better, https://github.com/apple/swift/pull/8908 <https://github.com/apple/swift/pull/8908>. Thanks for catching this!
>
> Jordan
>
>
>> On May 9, 2017, at 07:09, Pushkar N Kulkarni via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>>
>> Hi there,
>>
>> I see a new warning message for switch statements on enums, like this one:
>>
>> enum Test {
>> case one(Any)
>> case two
>> }
>>
>> let x: Test = .one("One")
>> switch x {
>> case .one(let s as String): print(s)
>> case .one: break
>> case .two: break
>> }
>>
>> enum.swift:9:10: warning: case is already handled by previous patterns; consider removing it
>> case .one: break
>>
>>
>> I do not see this warning with the 04-24 dev snapshot.
>>
>> The warning goes away with the use of the wildcard pattern in the second case:
>>
>> switch x {
>> case .one(let s as String): print(s)
>> case .one(_): break
>> case .two: break
>> }
>>
>>
>> I am wondering if this change is intentional, though it does make sense to me. Can someone please point me to the related commit?
>>
>> Thanks in advance!
>>
>> Pushkar N Kulkarni,
>> IBM Runtimes
>>
>> Simplicity is prerequisite for reliability - Edsger W. Dijkstra
>>
>>
>> _______________________________________________
>> swift-dev mailing list
>> swift-dev at swift.org <mailto:swift-dev at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170509/386d8cd5/attachment.html>
More information about the swift-dev
mailing list