Skip to content

Commit 8beaad6

Browse files
committed
[embedded] Allow casting to tuples
1 parent 0197784 commit 8beaad6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,7 @@ func isCastSupportedInEmbeddedSwift(from sourceType: Type,
10101010
return false
10111011
}
10121012

1013-
// Tuple?
1014-
if !destType.isStruct && !destType.isClass && !destType.isEnum {
1013+
if !destType.isStruct && !destType.isClass && !destType.isEnum && !destType.isTuple {
10151014
return false
10161015
}
10171016

test/embedded/existential.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ func test11(_ p: any Any) {
258258
let c = p as! SubClass
259259
c.foo()
260260
}
261+
262+
func test12(_ p: any Any) {
263+
print("test any as! (Int, Int, Int, Int)")
264+
if let c = p as? (Int, Int, Int, Int) {
265+
print("success")
266+
print("tuple: \(c.0)")
267+
} else {
268+
print("cast failed")
269+
}
270+
}
271+
261272
@main
262273
struct Main {
263274
static func main() {
@@ -372,5 +383,9 @@ struct Main {
372383
// OUTPUT: SubClass.foo
373384
// OUTPUT: BaseClass.deinit
374385
// OUTPUT-NOT: deinit
386+
test12((0, 1, 2, 3))
387+
// OUTPUT: test any as! (Int, Int, Int, Int)
388+
// OUTPUT: success
389+
// OUTPUT: tuple: 0
375390
}
376391
}

0 commit comments

Comments
 (0)