Skip to content

[SR-11160] Inconsistent behavior with exhaustive switching over optionals of tuples #53557

@tayloraswift

Description

@tayloraswift
Previous ID SR-11160
Radar rdar://problem/53312914
Original Reporter @Kelvin13
Type Bug
Status Resolved
Resolution Done
Environment

$ swift --version
Swift version 5.1-dev (LLVM 200186e28b, Swift 75a5496)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @typesanitizer
Priority Medium

md5: 17cc87614deb65870fadbaf0dd67d61d

is blocked by:

  • SR-11212 Ill-typed patterns are permitted to compile (implicit tupling/untupling)

Issue Description:

why does this work:
{{}}

func foo<T, U>(_ bar1:T?, _ bar2:U?) 
{
    switch (bar1, bar2) 
    { 
    case (let a?, let b?):
        print(a, b) 
    case (let a?, nil): 
        print(a, -1) 
    case(nil, let b?):
        print(-1, b) 
    case (nil, nil): 
        print("") 
    } 
}

{{}}
but not this?

switch (Optional<Int>(1), Optional<(Int, Int)>((5, 6))) 
{ 
case (let a?, let b?):
    print(a, b) 
case (let a?, nil): 
    print(a, -1) 
case(nil, let b?):
    print(-1, b) 
case (nil, nil): 
    print("") 
} 
error: switch must be exhaustive
switch (Optional<Int>(1), Optional<(Int, Int)>((5, 6))) 
^
note: add missing case: '(_, .some(_, _))'
switch (Optional<Int>(1), Optional<(Int, Int)>((5, 6))) 

{{}}

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions