Skip to content

Commit 902409a

Browse files
committed
[test] Add a couple of tests for as? in an if/switch expr
1 parent eea590a commit 902409a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/SILGen/if_expr.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,12 @@ func testCaptureList() -> Int {
571571
let fn = { [x = if .random() { 0 } else { 1 }] in x }
572572
return fn()
573573
}
574+
575+
// https://github.com/apple/swift/issues/68764
576+
func testConditionalCast<T>(_ x: Any) -> T? {
577+
if .random() {
578+
x as? T
579+
} else {
580+
nil
581+
}
582+
}

test/SILGen/switch_expr.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,11 @@ func testCaptureList() -> Int {
767767
let fn = { [x = switch Bool.random() { case true: 0 case false: 1 }] in x }
768768
return fn()
769769
}
770+
771+
// https://github.com/apple/swift/issues/68764
772+
func testConditionalCast<T>(_ x: Any, _ y: Int) -> T? {
773+
switch y {
774+
default:
775+
x as? T
776+
}
777+
}

0 commit comments

Comments
 (0)