1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
// RUN: %target-run-simple-swift | %FileCheck %s
// REQUIRES: executable_test
// https://github.com/apple/swift/issues/53611
// Even though we test that type-checking and exhaustiveness checking work fine
// in the presence of implicit tupling/untupling in exhaustive_switch.swift,
// make sure that the "patched" patterns do not lead to incorrect codegen.
enum Untupled {
case upair(Int, Int)
}
let u_ex = Untupled.upair(1, 2)
func content_untupled_pattern_tupled1(u: Untupled) -> (Int, Int) {
switch u { case .upair((let x, let y)): return (x, y) }
}
print(content_untupled_pattern_tupled1(u: u_ex))
// CHECK: (1, 2)
func content_untupled_pattern_tupled2(u: Untupled) -> (Int, Int) {
switch u { case .upair(let (x, y)): return (x, y) }
}
print(content_untupled_pattern_tupled2(u: u_ex))
// CHECK: (1, 2)
func content_untupled_pattern_tupled3(u: Untupled) -> (Int, Int) {
switch u { case let .upair((x, y)): return (x, y) }
}
print(content_untupled_pattern_tupled3(u: u_ex))
// CHECK: (1, 2)
func content_untupled_pattern_untupled1(u: Untupled) -> (Int, Int) {
switch u { case .upair(let x, let y): return (x, y) }
}
print(content_untupled_pattern_untupled1(u: u_ex))
// CHECK: (1, 2)
func content_untupled_pattern_untupled2(u: Untupled) -> (Int, Int) {
switch u { case let .upair(x, y): return (x, y) }
}
print(content_untupled_pattern_untupled2(u: u_ex))
// CHECK: (1, 2)
func content_untupled_pattern_ambiguous1(u: Untupled) -> (Int, Int) {
switch u { case .upair(let u_): return u_ }
}
print(content_untupled_pattern_ambiguous1(u: u_ex))
// CHECK: (1, 2)
func content_untupled_pattern_ambiguous2(u: Untupled) -> (Int, Int) {
switch u { case let .upair(u_): return u_ }
}
print(content_untupled_pattern_ambiguous2(u: u_ex))
// CHECK: (1, 2)
enum Tupled {
case tpair((Int, Int))
}
let t_ex = Tupled.tpair((1, 2))
func content_tupled_pattern_tupled1(t: Tupled) -> (Int, Int) {
switch t { case .tpair((let x, let y)): return (x, y) }
}
print(content_tupled_pattern_tupled1(t: t_ex))
// CHECK: (1, 2)
func content_tupled_pattern_tupled2(t: Tupled) -> (Int, Int) {
switch t { case .tpair(let (x, y)): return (x, y) }
}
print(content_tupled_pattern_tupled2(t: t_ex))
// CHECK: (1, 2)
func content_tupled_pattern_tupled3(t: Tupled) -> (Int, Int) {
switch t { case let .tpair((x, y)): return (x, y) }
}
print(content_tupled_pattern_tupled3(t: t_ex))
// CHECK: (1, 2)
func content_tupled_pattern_untupled1(t: Tupled) -> (Int, Int) {
switch t { case .tpair(let x, let y): return (x, y) }
}
print(content_tupled_pattern_untupled1(t: t_ex))
// CHECK: (1, 2)
func content_tupled_pattern_untupled2(t: Tupled) -> (Int, Int) {
switch t { case let .tpair(x, y): return (x, y) }
}
print(content_tupled_pattern_untupled2(t: t_ex))
// CHECK: (1, 2)
func content_tupled_pattern_ambiguous1(t: Tupled) -> (Int, Int) {
switch t { case .tpair(let t_): return t_ }
}
print(content_tupled_pattern_ambiguous1(t: t_ex))
// CHECK: (1, 2)
func content_tupled_pattern_ambiguous2(t: Tupled) -> (Int, Int) {
switch t { case let .tpair(t_): return t_ }
}
print(content_tupled_pattern_ambiguous2(t: t_ex))
// CHECK: (1, 2)
enum Box<T> {
case box(T)
}
let b_ex : Box<(Int, Int)> = Box.box((1, 2))
func content_generic_pattern_tupled1(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case .box((let x, let y)): return (x, y) }
}
print(content_generic_pattern_tupled1(b: b_ex))
// CHECK: (1, 2)
func content_generic_pattern_tupled2(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case .box(let (x, y)): return (x, y) }
}
print(content_generic_pattern_tupled2(b: b_ex))
// CHECK: (1, 2)
func content_generic_pattern_tupled3(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case let .box((x, y)): return (x, y) }
}
print(content_generic_pattern_tupled3(b: b_ex))
// CHECK: (1, 2)
func content_generic_pattern_untupled1(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case .box(let x, let y): return (x, y) }
}
print(content_generic_pattern_untupled1(b: b_ex))
// CHECK: (1, 2)
func content_generic_pattern_untupled2(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case let .box(x, y): return (x, y) }
}
print(content_generic_pattern_untupled2(b: b_ex))
// CHECK: (1, 2)
func content_generic_pattern_ambiguous1(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case .box(let b_): return b_ }
}
print(content_generic_pattern_ambiguous1(b: b_ex))
// CHECK: (1, 2)
func content_generic_pattern_ambiguous2(b: Box<(Int, Int)>) -> (Int, Int) {
switch b { case let .box(b_): return b_ }
}
print(content_generic_pattern_ambiguous2(b: b_ex))
// CHECK: (1, 2)
|