i had always assumed that
case wrapped:
promotes to
case wrapped?:
if the switch parameter is optional.
so i was surprised that the following causes a compiler error:
func test1(bool:Bool?)
{
switch bool
{
case nil, true:
break
case false:
break
}
}
switch.swift:3:5: error: switch must be exhaustive
switch bool
^
switch.swift:3:5: note: add missing case: '.some(_)'
switch bool
instead it must be written as:
func test2(bool:Bool?)
{
switch bool
{
case nil, true?:
break
case false?:
break
}
}
why?
1 Like
Also asked at the end of this post. Not answered.
1 Like
Jumhyn
(Frederick Kellison-Linn)
3
Looks like a bug to me, I don’t see any reason why this switch shouldn’t be considered exhaustive.
1 Like